Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取会话数据时的cakephp问题_Php_Session_Cakephp - Fatal编程技术网

获取会话数据时的cakephp问题

获取会话数据时的cakephp问题,php,session,cakephp,Php,Session,Cakephp,在我的项目中,我使用以下方法从会话中存储和获取数据 要写入数据: $this->Session->write('data', array('title'=>'Abc')); 要读取数据: $this->Session->read('data')['title']; 而且它在live server上仍然可以正常工作。2天前,我将代码转移到了另一个live服务器上。现在,此服务器在上显示致命错误 $this->Session->read('data')['title

在我的项目中,我使用以下方法从会话中存储和获取数据

要写入数据:

$this->Session->write('data', array('title'=>'Abc'));
要读取数据:

$this->Session->read('data')['title'];
而且它在live server上仍然可以正常工作。2天前,我将代码转移到了另一个live服务器上。现在,此服务器在上显示致命错误
$this->Session->read('data')['title']即意外[]

然后我在谷歌上搜索,发现还有其他方法可以获取索引,例如

$this->Session->read('data.title');
如果
$this->Session->read('data')['title']
是错误的方式,那么它仍然在我的旧服务器上工作


提前感谢。

[]
PHP5.4
这是一个简短的语法,在
PHP<5.4
中无法使用

资料来源:




这是你要找的。我在匆忙中发布了上述内容

从PHP5.4开始,可以直接对函数或方法调用的结果进行数组解引用。在此之前,只能使用临时变量



例如:

function getArray() {
    return array(1, 2, 3);
}

// on PHP 5.4
$secondElement = getArray()[1];

// previously
$tmp = getArray();
$secondElement = $tmp[1];

请提及您的cakephp和php版本。这听起来像是php版本的差异。您当前使用的是什么版本,旧服务器上使用的是什么?新服务器的php版本是:5.3.32.0,旧服务器的:5.4.162.0您认为是因为版本?