【发布时间】:2014-03-05 11:03:12
【问题描述】:
所以...前几天我推送了一些代码(在我的本地机器上运行 100% 正常)但终止了服务器 - 没有 Codeigniter 日志,没有 Apache 日志,die('msg') 和 exit() 没有工作 -在 5 年以上的 PHP 开发中,我从未经历过这种情况。
在我的 repo 提交了 50 多次后,我将问题缩小到一个语句,该语句在拆分时有效,但不能一起使用。
系统信息:
PHP 版本:5.4.13
Codeigniter 版本:
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 错误?
结构:
Main.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);
// }
}
}
adminstration.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();
}
}
【问题讨论】:
-
empty 测试变量,没有返回值....除非您运行的是 PHP >= 5.5
-
天啊... 20 多小时才弄清楚。将其添加为答案,我很乐意接受。
-
踢自己? :) 它发生在我们所有人身上
-
虽然看不出这将如何“不引人注意”——它应该给出一个非常明显的错误消息,例如 “致命错误:无法在写入上下文中使用函数返回值” 或 “Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$'” 取决于 PHP 版本,请参阅3v4l.org/rpIkn – 你确定你的错误报告配置正确......?
标签: php codeigniter codeigniter-2