Tag: PHP的

你可以提示一个数组的项目types?

这个问题与这个问题有关: 是否有可能暗示返回数组中的项目的types? 例如: /** * MyFunction does a lot of things * * @param TClass1 $var1 * @param TClass2 $var2 * @return array[TClass3] //<- I'm trying to express this */ function MyFunction( $var1, $var2 ){ … 我正在使用NetBeans作为一个IDE,它需要(像很多其他PHP IDE一样)function上面的文档块来确定返回值的types。 如果我可以解释一个数组中的期望types,我希望IDE能够为以下情况提供正确的完成: $myTab = MyFunction( $foo, $bar ); foreach( $myTab as $itm ){ $itm->myFi| //offer the completion for […]

如何处理魔法实现方法中的“类中找不到的方法”警告?

我坐在一个大型的代码库上,这个代码库包含了几个通过魔法实现的方法公开function的类(使用__call和__callStatic )。 例如: class Foo { public function __call($name, $parameters) { echo "You called $name().\n"; } } $f = new Foo; $f->test(); // runs fine, but PhpStorm flags as a warning 问题是PhpStorm认为test()方法不存在,所以它在呼叫站点发出警告。 这有点烦人,因为代码当然会按预期运行。 我已经通过检查“如果在类中存在__magic方法的降级严重性”来调整严重性,但是我更愿意: 完全禁用此function只为特定的类,或 使用IDE而不是反对它 – 提供我已有的信息,以便我们的观点达成一致 以上是否有可能? 如果是这样,怎么样? 额外的奖金问题:考虑方法调用被链接的情况。 $f = new Foo; $f->test()->chain()->moreChain(); // potentially runs fine 假设对$f->test()的魔术调用返回适当的后续(可能,但不一定,也是魔术)调用将正常工作。 但是,由于我不知道告诉IDE什么是test()它将其余的调用链标记为缺less的方法。 更糟的是,“降级严重性”设置不适用于这些警告,因为IDE不知道这些中间对象应该是什么类。 有没有可以解决这个问题的解决scheme? 更新 […]

处理php页面错误的最佳方法?

现在我的网页看起来像这样: if($_GET['something'] == 'somevalue') { $output .= 'somecode'; // make a DB query, fetch a row //… $row = $stmt->Fetch(PDO::ASSOC); if($row != null) { $output .= 'morecode'; if(somethingIsOK()) { $output .= 'yet more page output'; } else { $error = 'something is most definitely not OK.'; } } else { $error = 'the row does […]

Kohana 3:validation模型的例子

我find关于模型和validation的例子和教程。 而我所说的validation(或者至less大部分)应该在模型中,我同意这一点。 但我不能有任何示例或教程来说明应该如何完成。 任何人都可以帮助我一个简单的例子,如何做到这一点? 你在哪里有模型的规则? validation会在哪里发生? 控制器如何知道validation是否通过? 控制器如何得到错误信息和类似的东西? 希望有人能帮忙,让这里感觉有点失落:p

为什么自PHP 5.4起永久启用“echo”短标签?

即使是官方文档告诉我们PHP“短标签”( <? /*…*/ ?> )是“坏”的 。 但是, 从PHP 5.4起,无论short_open_tag设置如何,都会永久启用echotypes<?= /*…*/ ?> 。 什么改变了? 即使他们之前仅仅因为在共享主机平台上是否启用了short_open_tag而具有不可预知的性质,当然这个参数不会因为一些主机子集将运行PHP 5.4而消失。 可以说,语言的这种改变本身并不意味着build议的改变,我们应该避免使用“短标签”,但是如果他们遇到了麻烦,PHP开发者似乎不再“讨厌”许多。 对? 我现在可以得出的唯一合乎逻辑的结论是,在PHP 5.4中引入这个变化必定有一些客观的基本原理。 它是什么?

CakePHP cake_core_ cache无法写入“cake_dev_en-us”

我已经尝试了一切,但我不断收到以下蛋糕错误: ( ! ) Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /var/www/bloglic-2013/cake/lib/Cake/Cache/Cache.php on line 309 Warning: /var/www/bloglic-2013/cake/app/tmp/cache/persistent/ is not writable in /var/www/bloglic-2013/cake/lib/Cake/Cache/Engine/FileEngine.php on line 336 ( ! ) Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /var/www/bloglic-2013/cake/lib/Cake/Cache/Cache.php on line 165 ( ! ) […]

由于模块和PHP的API在更改PHPconfiguration后不匹配,因此Apache“无法初始化模块”

php -v给出这个 PHP Warning: PHP Startup: memcache: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20090626 These options need to match in Unknown on line 0 PHP Warning: PHP Startup: memcache: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20090626 These options need to match […]

C#SHA-1与PHP SHA-1 …不同的结果?

我想从一个string计算一个SHA-1哈希,但是当我使用php的sha1函数计算string时,我得到了与在C#中尝试不同的东西。 我需要C#来计算相同的string作为PHP(因为PHP的string是由第三方计算,我不能修改)。 我如何让C#生成与PHP相同的散列? 谢谢!!! string= s934kladfklada@a.com C#代码(生成d32954053ee93985f5c3ca2583145668bb7ade86) string encode = secretkey + email; UnicodeEncoding UE = new UnicodeEncoding(); byte[] HashValue, MessageBytes = UE.GetBytes(encode); SHA1Managed SHhash = new SHA1Managed(); string strHex = ""; HashValue = SHhash.ComputeHash(MessageBytes); foreach(byte b in HashValue) { strHex += String.Format("{0:x2}", b); } PHP代码(生成a9410edeaf75222d7b576c1b23ca0a9af0dffa98) sha1();

例外:不允许序列化“closures”

所以我不确定我要告诉你们什么,如果你需要更多的代码,请不要犹豫,问问: 所以这个方法将在我们的应用程序中为Zend设置initMailer: protected function _initMailer() { if ('testing' !== APPLICATION_ENV) { $this->bootstrap('Config'); $options = $this->getOptions(); $mail = new Zend_Application_Resource_Mail($options['mail']); }elseif ('testing' === APPLICATION_ENV) { //change the mail transport only if dev or test if (APPLICATION_ENV <> 'production') { $callback = function() { return 'ZendMail_' . microtime(true) .'.tmp'; }; $mail = new Zend_Mail_Transport_File( array('path' => '/tmp/mail/', […]

在Laravel 4中将一个Eloquent模型作为JSON返回

你如何将一个Eloquent模型作为JSON返回给浏览器? 以下两种方法有什么区别? 两者似乎工作。 #1: return Response::json($user->toArray()); #2: return $user->toJson();