Tag: PHP的

PHPUnit:在testingdebugging期间的CLI输出可能吗?

当运行一个PHPUnittesting,我想能够转储输出,所以我可以debugging一个或两个东西。 我已经尝试了以下(类似于PHPUnit手册示例 ); class theTest extends PHPUnit_Framework_TestCase { /** * @outputBuffering disabled */ public function testOutput() { print_r("Hello World"); print "Ping"; echo "Pong"; $out = "Foo"; var_dump($out); } } 结果如下: PHPUnit @package_version@ by Sebastian Bergmann. . Time: 0 seconds, Memory: 3.00Mb OK (1 test, 0 assertions) 注意没有预期的输出。 截至2011年9月19日,我正在使用git回购版的HEAD版本。 php -version输出: $ php -version PHP 5.2.9 […]

在MySQL Linux服务器上安装PDO驱动程序

不久前,我build议改变我的代码使用PDO为了参数化我的查询并安全地将HTML保存在数据库中。 那么,这里是主要的问题: 我看了http://php.net/manual/en/ref.pdo-mysql.php ,我真的不知道应该把$ ./configure –with-pdo-mysqlstring放在哪里。 我正在build设的网站实际上只需要一个页面的PDO。 虽然我可能会考虑重写它,但这需要一段时间,我需要很快的页面运行,所以我不能完全closuresMySQL。 如果我安装PDO,我仍然可以使用mysql_*处理程序? 有问题的服务器运行PHP版本5.4.6-1ubuntu1和Apache / 2.2.22(Ubuntu)。 如果它很重要,我也运行一个phpMyAdmin数据库。

运行作曲者时禁用xdebug

运行composer diagnose ,出现以下错误: xdebug扩展被加载,这可能会减慢Composer的速度。 build议使用Composer禁用它。 我只有在运行Composer时才能禁用xdebug?

你能退出一个循环在PHP中?

我有一个循环,在我的PHP代码中做一些错误检查。 原来它看起来像这样… foreach($results as $result) { if (!$condition) { $halt = true; ErrorHandler::addErrorToStack('Unexpected result.'); } doSomething(); } if (!$halt) { // do what I want cos I know there was no error } 这一切都运行良好,但它仍然循环,尽pipe一个错误后它不需要。 有没有办法摆脱循环?

在PHP中将stringparsing为布尔值

今天我在玩PHP,发现string值“true”和“false”在一个条件下没有被正确地parsing为布尔值,例如考虑下面的函数: function isBoolean($value) { if ($value) { return true; } else { return false; } } 如果我执行: isBoolean("true") // Returns true isBoolean("") // Returns false isBoolean("false") // Returns true, instead of false isBoolean("asd") // Returns true, instead of false 它似乎只适用于“1”和“0”值: isBoolean("1") // Returns true isBoolean("0") // Returns false 在PHP中有一个本地函数来parsing“true”和“false”string为布尔值吗?

如何在php中添加24小时到unix时间戳?

现在我想添加24小时的时间戳。 我如何find24小时的unix时间戳编号,所以我现在可以将它添加到时间戳? 我也想知道如何添加48小时或多天到当前的时间戳。 我怎样才能做到这一点最好?

明确的方式来获取用户的IP地址的PHP

可能重复: 获取用户IP地址的函数 <?PHP $ipaddress = $_SERVER["REMOTE_ADDR"]; echo "Your IP is $ipaddress!"; ?> 我被告知这种获取IP地址的方式有可能被骗的问题。 有没有更好的方法来收集IP地址? 寻找更好的方法来获取IP地址的教程?

PHP静态函数

我有一个关于在PHP静态function的问题。 让我们假设我有一个class级 class test { public function sayHi() { echo 'hi'; } } 如果我test::sayHi(); 它工作没有问题。 class test { public static function sayHi() { echo 'hi'; } } test::sayHi(); 也适用。 第一课和第二课有什么区别? 静态函数有什么特别之处?

将数据传递给Laravel 4中的一个闭包

我试图在Laravel 4中使用邮件类,我无法将variables传递给$ m对象。 $ team对象包含我从数据库中获取的数据,并且有口才。 Mail::send('emails.report', $data, function($m) { $m->to($team->senior->email, $team->senior->first_name . ' '. $team->senior->last_name ); $m->cc($team->junior->email, $team->junior->first_name . ' '. $team->junior->last_name ); $m->subject('Monthly Report'); $m->from('info@website.com', 'Sender'); }); 出于某种原因,我得到一个错误$团队对象不可用。 我想这与范围有关。 有任何想法吗 ?

json_encode / json_decode – 在PHP中返回stdClass而不是Array

观察这个小脚本: $array = array('stuff' => 'things'); print_r($array); //prints – Array ( [stuff] => things ) $arrayEncoded = json_encode($array); echo $arrayEncoded . "<br />"; //prints – {"stuff":"things"} $arrayDecoded = json_decode($arrayEncoded); print_r($arrayDecoded); //prints – stdClass Object ( [stuff] => things ) 为什么PHP把JSON对象变成一个类? 不应该是json_encoded然后json_decoded的数组产生EXACT相同的结果?