note 96098 modified in language.references.pass by danbrown

From: Date: Mon, 08 Feb 2010 22:16:31 +0000
Subject: note 96098 modified in language.references.pass by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165767@lists.php.net to get a copy of this message
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! ?> --was-- Watch out that passing an uninitialised variable to a function will create the variable and will NOT give a NOTICE-undefined variable: 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! http://php.net/manual/en/language.references.pass.php

« previous php.notes (#165767) next »