For instance (using the isset_or_default()) call:
$nCustID = (int) isset_or_default($_POST['CUST_ID'], 0);
That would give the developer flexibility on how he used it, and could reassign it to the $_POST array if he wanted to.
$_POST['CUST_ID'] = (int) isset_or_default($_POST['CUST_ID'], 0);
I agree that it would be helpful not to evaluate the second parameter unless needed, which is why I originally proposed a language construct.
Also, I think that using an operator would add to the complexity of thoroughly understanding the PHP language, which is something that I understand we do not want to do.
~Jason Garber
At 4/15/2004 02:34 PM -0400, Ilia Alshanetsky wrote:
On April 15, 2004 02:15 pm, Andi Gutmans wrote: > It could be implemented but I don't see the big advantage over $bar ? 0 : > $base It's one character...
Well, currently to check the value and assign the default you need to do the following:
$_GET['foo'] = isset($_GET['foo']) ? (int) $_GET['foo'] : 0;
Which can get quite annoying if you need to repeat that many times and it's just easier to disable notices and do $_GET['foo'] = (int) $_GET['foo'];
I think if anyone of the following would work it would be quite convenient
isset_or_default($_GET['foo'], 0); /* if $_GET['foo'] is set leave as is, otherwise assign 0 to it */
$_GET['foo'] = isset_or_default($_GET['foo'], 0); /* same as above, but the variable is not passed by reference */
isset($_GET['foo']) ? : 0; /* Sascha's proposal */
Ilia
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php