所以...前几天我推送了一些代码(在我的本地机器上 100% 正常工作)但是杀死了服务器 - 没有 Codeigniter 日志,没有 Apache 日志,die('msg')
和 exit()
不起作用 - 我在 5 年以上的 PHP 开发中从未遇到过这种情况。
在 50 多个提交到我的 repo 之后,我将问题缩小到一个声明,该声明在拆分时有效,但在合并时无效。
系统信息:
PHP Version: 5.4.13
Codeigniter Version:
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只作用于变量,而不作用于函数的返回值或直接作用于表达式的结果
关于PHP 版本 5.4.13 错误?代码点火器错误?或者,解释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21637840/