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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Please explain this behavior of unserialize

    PHP Code:
    <?php

      $foo 
    unserialize('');

      echo 
    count($foo);
      
    // echoes 1

      
    print_r($foo);
      
    // echoes nothing

    ?>

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Unserialize is used on arrays that have been serialized.

  • #3
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    from the manual on count:
    If var is not an array or an object with implemented Countable interface, 1 will be returned.
    and in your example $foo will be set to boolean false, so it cannot be "counted".


  •  

    Posting Permissions

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