Alban wrote:
> Le Sat, 21 Nov 2009 10:21:18 -0800, Rasmus Lerdorf a écrit :
>> The ternary isn't meant to solve the isset thing you are talking about.
>>  It is simply a shortcut to normal ternary operations.  The most common
>> case where you don't know if a variable is set is on the initial input
>> via $_GET or $_POST and we definitely don't want people doing:
>>
>>   $var = $_GET['foo'] ?: 42;
>>
>> It would be an XSS disaster.  Hence the suggestion to use input_filter
>> there, or a similar user-supplied filtering function in which case the
>> ternary, as it is currently implemented, is perfectly suitable.
>>
>> -Rasmus
> 
> Sure ! Developpers should filter variables contents !
> 
> Generaly there are 3 step for treat incoming variable : 
> 1- checking existance of the variable. 
> 2- set a default value if it not exists or empty. 
> 3- filtering the variable content.

Or better yet, have your filter function return false if the variable
doesn't exist and use the ternary to set the default.  You can do it all
in a single step then.

$var = filter_func($_GET,'foo')?:42;

Simple and clean.

-Rasmus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to