SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Isset always return false for object even they declared

    Why isset on object variable always return false even they declared?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,034
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Hi gede, welcome to the forums,

    http://php.net/manual/en/function.isset.php
    Returns TRUE if var exists and has value other than NULL, FALSE otherwise.
    if you try something like
    PHP Code:
    $my_obj = new $Object;
    echo isset(
    $my_obj);
    var_dump($my_obj); 
    what do you get?

  3. #3
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh I see..
    I figure out the problem now.. the problem is in my class have magic method __get()

    class myClass{
    var $data = array('key' => 1);
    function __get($key)
    {
    return (isset($this->data[$key])) ? $this->data[$key] : false;
    }
    }
    $my_obj = new myClass();
    var_dump(isset($my_obj->key));
    echo $my_obj->key;
    that make me confused, when I echo it's return value, but return false from isset()
    Does my code normally?


Bookmarks

Posting Permissions

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