|
Posted by Jerry Stuckle on 05/12/07 14:03
Rami Elomaa wrote:
> Mike P2 kirjoitti:
>> On May 11, 1:28 am, Toby A Inkster <usenet200...@tobyinkster.co.uk>
>> wrote:
>>> Mike P2 wrote:
>>>> This will allow you to use more than one candidate as you mentioned,
>>>> and PHP will not issue a notice this way.
>>> That's quite clever code, but it will only work when called from the
>>> global scope.
>>>
>>> --
>>> Toby A Inkster BSc (Hons) ARCShttp://tobyinkster.co.uk/
>>> Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
>>
>> Then I think using a function for this, although it would be useful,
>> is hopeless without making a PHP extension in C++. Maybe this could be
>> a suggestion to the PHP developers as a keyword in the future.
>
> Rather than adding a new function, I'd prefer an operator that would
> select from a list of variables the first one that is set. For example
>
> $foo = $_SESSION['foo'] ?: $_GET['foo'] ?: $_POST['foo'] ?: 'default';
>
> which would be the same as
>
> $foo = isset($_SESSION['foo']) ? $_SESSION['foo'] :
> (isset($_GET['foo']) ? $_GET['foo'] :
> (isset($_POST['foo']) ? $_POST['foo'] : 'default'));
>
> Or
>
> if(isset($_SESSION['foo'])) {
> $foo = $_SESSION['foo'];
> } else if (isset($_GET['foo'])) {
> $foo = $_GET['foo'];
> } else if (isset($_POST['foo'])) {
> $foo = $_POST['foo'];
> } else {
> $foo = 'default;
> }
>
> The operator ?: would perform isset on the first operand and return it
> if succesful, else it would return the second expression. Any php
> developers out there? Wink wink, this would be a nice new feature for
> php 6...
>
Interesting idea. Not sure how much I'd use it, but I can see it has
possibilities.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|