note 96098 deleted from language.references.pass by googleguy

From: Date: Sun, 23 Feb 2014 17:22:06 +0000
Subject: note 96098 deleted from language.references.pass by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198609@lists.php.net to get a copy of this message
Note Submitter: rvw at cosninix dot com ---- Watch out that passing an uninitialised variable to a function will create the variable and will NOT give a NOTICE-undefined variable: <?php function ifnull(&$v,$default) { if (isset($v)) return $v; return $default; } $p=array(); $p['apple']=3; echo ifnull($p['apple'],4); -> 3 echo ifnull($p['pear'],5); -> 5 No "undefined index" here. if (isset($p['pear'])) echo "pear is set"; else echo "pear not set"; -> not set if (array_key_exists('pear',$p)) echo "pear exists"; else echo "pear doesn't exist"; -> pear exists! ?>

« previous php.notes (#198609) next »