...

View Full Version : String offset fatal error in PHP 5.0.5



bauhsoj
04-24-2006, 09:41 PM
I am receiving the fatal error "Cannot use string offset as an array" when executing code that checks if an array element is empty that is at least three arrays deep. This fatal error only happens if the variable could potentially be an empty string.

The code performs this check to determine if an unserialized array was pulled from a database record that is ordinarily nothing but an empty string value. The array that is sometimes stored can be many levels deep. However, this error doesn't occur with PHP 4.3.4 or PHP 5.1.2, only PHP 5.0.5 as I have tested the exact same code on all of them.

For instance, the following causes the fatal error:
$something = array('element1'=>'');

if (empty($something['element1']['next']['again']['last']))
echo "<p>last element didn't exist</p>";
else
echo "<p>last element DID exist</p>";

The following also causes the fatal error:
$something = "";

if (empty($something['element1']['next']['last']))
echo "<p>last element didn't exist</p>";
else
echo "<p>last element DID exist</p>";

Note that is has to be at least three array elements deep before the fatal error occurs from the check in the empty() condition.

Is this a known bug with PHP or is there something wrong with the server configuration?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum