Re: what happened to that new isset() like language
| From: | Cris H | Date: | Fri, 09 Jul 2004 19:07:53 +0000 |
| Subject: | Re: what happened to that new isset() like language | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-11038@lists.php.net to get a copy of this message | ||
Isn't this problem solvable with just a "User Space" function?
<?php
error_reporting(E_ALL);
function ifsetor(&$variable, $alternate = NULL){
if(isset($variable)){
$tmp = $variable;
echo('<p>$variable exists.</p>');
}
else{
$tmp = $alternate;
echo('<p>no $variable here.</p>');
}
return $tmp;
}
// no errors thrown ...
$nonexistent = ifsetor($nonexistent);
ifsetor($randomNonexistent);
if($nonexistent !== NULL)
echo('<p>$nonexistent is NOT NULL</p>');
else
echo('<p>$nonexistent is NULL</p>');
?>
Because, as Derick Rethans mentioned, arguments passed by
reference will not trigger the Undefined (variable | index)
Notice at the point of the function call, and also PHP's C++
style default arguments providing the alternate value, surely
the above code would suffice?
Apologies if I've completely misunderstood (with certainty a
non-zero probability)...
Regards,
Cris
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many
all-new ways to express yourself http://uk.messenger.yahoo.com