所以...前几天我实时推送了一些代码(在我的本地机器上工作 100% 正常),但杀死了服务器 - 没有 Codeigniter 日志,没有 Apache 日志,die('msg')
和 exit()
不起作用 - 我以前从未经历过这种情况在 5+ 年的 PHP 开发中。
在 50+ 提交到我的 repo 后,我将问题缩小到一个语句,该语句在拆分时有效,但不能一起工作。
系统信息:
PHP 版本: 5.4.13
代码点火器版本:
define('CI_VERSION', '2.1.3');
这些行有效(在 Codeigniter MY_Controller 函数中调用):
dump($this->get_val('order_id'));
$tmp = $this->get_val('order_id');
dump($tmp);
dump(empty($tmp));
dump(!empty($tmp));
但是当我添加以下行时,会发生上述崩溃:
!empty($this->get_val('order_id'))
这似乎是一个PHP错误?
<小时 />结构:
主.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Main extends Administration {
function index() {
// if (!empty($in['order_id'])) { /* BROKEN */
dump($this->get_val('order_id'));
$tmp = $this->get_val('order_id');
dump($tmp);
dump(empty($tmp));
dump(!empty($tmp));
// dump(!empty($this->get_val('order_id'))); /* BROKEN */
// if (!empty($this->get_val('order_id'))) { /* BROKEN */
// dump(true);
// } else {
// dump(false);
// }
}
}
管理.php
<?php
class Administration {
/**
*
* @var MY_Controller;
*/
public $ci;
public $p;
function __construct() {
$this->ci = & get_instance();
$this->ci->load->model('user/admin/user_admin_model');
$this->p = $this->ci->uri->uri_to_assoc(4);
}
protected function get_val($name = '') {
$pst = (array) $this->ci->input->post();
$gt = (array) $this->ci->input->get();
if (empty($name)) {
return array_merge($pst, $gt, $this->p);
}
if (!empty($this->p[$name]))
return $this->p[$name];
if (!empty($pst[$name]))
return $pst[$name];
if (!empty($gt[$name]))
return $gt[$name];
return array();
}
}
?>
My_Controller.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
protected $p;
function __construct() {
parent::__construct();
$this->p = $this->uri->uri_to_assoc();
}
function get_val($name = '') {
dump("I am get_val in MY_controller");
$pst = (array) $this->input->post();
$gt = (array) $this->input->get();
if (empty($name)) {
return array_merge($pst, $gt, $this->p);
}
if (!empty($this->p[$name]))
return $this->p[$name];
if (!empty($pst[$name]))
return $pst[$name];
if (!empty($gt[$name]))
return $gt[$name];
return array();
}
}
在 PHP 版本 5.5.0 之前,empty 仅适用于变量,不适用于函数的返回值或直接用于表达式的结果