Cannot use [] for reading

Viewed 73033

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

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

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.

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

7 Answers

I had same error with following:

echo implode(',', $array[]);

which should have been

echo implode(',', $array);

Hope this can help someone

Related