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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Cris H wrote:
| Isn't this problem solvable with just a "User Space" function?
[snip]
| 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)...
|
I understand that this is not sufficient because of the following
circumstance:
$var = ifsetor($_GET['test'], foo());
foo() is ALWAYS evaluated with the user-space function you wrote. I
understand that we don't want foo() to be called unless it needs to be
returned (ie, we want to be able to short circuit the parameters)?
Now, maybe I'M misunderstanding? (-: I don't have much knowledge of
internals, but is this even POSSIBLE as a function call, and not as an
operator?
S
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFA7u+JWppknrQMxQIRAg1KAJ4tApnlVxsD/2Sc/3HubJtzFsp9tQCglqXZ
93qdums+B43W1Rpgjp1hLMg=
=91eL
-----END PGP SIGNATURE
That would satisfy some of the requested feature, but try
calling ifsetor($my_array['bad key'], functionWithSideEffects()).
Marcus has repeatedly mentioned that the requested feature is
hard (bordering on impossible) to implement, but in the requested
feature (if I understand it (and it is what I would ask for too :) )),
there would be no error for using a key that isn't in the array,
there would be no side effect of creating a key in the array, and
if the $my_array['bad key'] actually did happen to be non-NULL,
the function with the side effects wouldn't get called.
That would be really handy, especially if it could take a variable
number of arguments. Using a standard name like coalesce would
be nice.
BTW, I have no weight around here; just thought I could help
clarify, having following this thread with interest...
- Todd
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