note 101536 added to function.isset

From: Date: Thu, 23 Dec 2010 03:21:53 +0000
Subject: note 101536 added to function.isset
Groups: php.notes 
Request: Send a blank email to php-notes+get-175155@lists.php.net to get a copy of this message
Now this is how to achieve the same effect (ie, having isset() returning true even if variable has been set to null) for objects and arrays <?php // array $array=array('foo'=>null); return isset($array['foo']) || array_key_exists('foo',$array) ? true : false ; // return true return isset($array['inexistent']) || array_key_exists('inexistent',$array) ? true : false ; // return false // static class class bar { static $foo=null; } return isset(bar::$foo) || array_key_exists('foo',get_class_vars('bar')) ? true : false ; // return true return isset(bar::$inexistent) || array_key_exists('inexistent',get_class_vars('bar')) ? true : false ; // return false // object class bar { public $foo=null; } $bar=new bar(); return isset($bar->foo) || array_key_exists('foo',get_object_vars($bar)) ? true : false ; // return true return isset($bar->inexistent) || array_key_exists('inexistent',get_object_vars($bar)) ? true : false ; // return true // stdClass $bar=new stdClass; $bar->foo=null; return isset($bar->foo) || array_key_exists('foo',get_object_vars($bar)) ? true : false ; // return true return isset($bar->inexistent) || array_key_exists('inexistent',get_object_vars($bar)) ? true : false ; // return true ?> ---- Server IP: 80.64.47.13 Probable Submitter: 95.61.51.75 ---- Manual Page -- http://www.php.net/manual/en/function.isset.php Edit -- https://master.php.net/note/edit/101536 Del: integrated -- https://master.php.net/note/delete/101536/integrated Del: useless -- https://master.php.net/note/delete/101536/useless Del: bad code -- https://master.php.net/note/delete/101536/bad+code Del: spam -- https://master.php.net/note/delete/101536/spam Del: non-english -- https://master.php.net/note/delete/101536/non-english Del: in docs -- https://master.php.net/note/delete/101536/in+docs Del: other reasons-- https://master.php.net/note/delete/101536 Reject -- https://master.php.net/note/reject/101536 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175155) next »