不能使用[]阅读 [英] Cannot use [] for reading

查看:768
本文介绍了不能使用[]阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的剧本之一,我尝试做以下

In one of my scripts, I try to do the following

$data[] = self::get($row['sr_id']); // <-- line 55

然而,PHP不允许我这样做,给我这个错误

However, PHP does not allow me to do this, giving me this error

Fatal error: Cannot use [] for reading in /file.php on line 55

自::获得函数返回一个布尔值,或对象。

The self::get function return either a bool, or an object.

编辑:get函数创建这再次从一个MySQL数据库加载数据的新对象。

The get function creates a new object which again loads data from a mysql database.

推荐答案

旧的PHP版本接受是$ var [] 中前pressions,允许读出 $ VAR 内容,不管语法。 PHP 5.1所做的违法行为。但有时错误被触发intented背景之外。结果
所以我的猜测(再次:显示更多code)的是,preceeding行包含一个未完成前pression,到了 $数据[] 连接。

Old PHP versions accepted $var[] in expressions, allowed reading out the $var content regardless of syntax. PHP 5.1 made that illegal. But sometimes the error is triggered outside of the intented context.
So my guess (again: show more code) is that the preceeding line contains an unfinished expression, to which the $data[] joins.

在对象的属性的情况下你可以用你的$的数据变种成 {} ,但似乎并没有被你的情况的问题。 (否则有东西在第54行,你没有显示)的右手边不能合理地触发错误。即使数组访问 [] 整数或对象不会触发致命的错误。

In case of object attribute you can wrap your $data var into { }, but that doesn't seem to be the problem in your case. (Else there is something in line 54, that you didn't show.) The right hand side can't reasonably trigger the error. Even array accessing [] an integer or object wouldn't trigger that fatal error.

所以,如果没有什么帮助,只要使用 array_push()。周围PHP的工作。

So if nothing helps, just use array_push(). Work around PHP.

这篇关于不能使用[]阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆