working - php<?=

Cannot use[] for reading (4)

Another possible problem could be an accidental double ==. For example accidentally doing $myArray[] == $myNewValue; would cause this error (because you are trying to read a value with the == instead of telling PHP to assign a new array index).

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.

I had the same problem with my script, the following line threw the same error:


I simply replaced it by


and it worked perfectly.

The error I got was:

Fatal error: Cannot use [] for reading in /pathtosite/drupal/sites/all/themes/zenui/templates/page.tpl.php on line 33

Sometime the problem is when you include a line like this:


This might happen if you are copying a variable name and forgot to comment out the line.

There was two problems:

1. Missing semicolon

2. $variable[] must set a variable

After fixing these two problems my code read:

$page['sidebar_first'][] = $value;

Don't forget to comment out line you are not using to help with the debugging process

Hope this helps fellow programmers like me!

The solution in my case was this:

  • Bad line:

$this->$ExtraTag[] = $fullscript;

  • Good line:

$this->{$ExtraTag}[] = $fullscript;


$this->ExtraTag[] = $fullscript;