Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    String offset fatal error in PHP 5.0.5

    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:
    PHP Code:
    $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:
    PHP Code:
    $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?
    Last edited by bauhsoj; 04-24-2006 at 09:46 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •