PHP 版本 5.4.13 错误?代码点火器错误?或者,解释?

标签 php codeigniter codeigniter-2

所以...前几天我推送了一些代码(在我的本地机器上 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/

相关文章:

codeigniter - CodeIgniter DB session 问题:sess_expire_on_close

php - Codeigniter REST 上传多张图片

PHP:可以在默认的 php.ini 文件中设置常量

javascript - 提交后刷新整个页面(Fancybox)

regex - CI 3.0.4 大 where_in 查询导致消息 : preg_match(): Compilation failed: regular expression is too large at offset)

codeigniter - 为什么 Flashdata 值在重定向到 Codeigniter 中的另一个函数时变为空值?

php - Codeigniter 表单验证验证后显示双重重复表单

javascript - 通过ajax成功函数设置为模态设置的值时不显示

php - bigquery php 客户端无法与 Apache 网页一起使用(Ubuntu 18.10 服务器)

php - 在 xhprof 忽略函数中使用正则表达式模式匹配