Hey there,

I've been working on a little patch that will allow variables ($1) in
a short-ternary operation to go through an implicit isset
(zend_do_isset_or_isempty) check so that the average use-case for the
short-ternary operator doesn't yield in a notice whenever the first
variable of the expression isn't set.

So the use-case I'm considering is the following:

<?php
    $list = array('name' => 'list');

    echo $list['name'] ?: 'List not set.' . PHP_EOL;
    echo $list['name-notset'] ?: 'List not set.' . PHP_EOL;
?>

This example, which we all know, will result in a notice for the
second echo statement because the requested array-key doesn't actually
exist in the array.

Now, looking at the original implementation thread of ifsetor and ?: I
can see that Marcus' patch had an implicit isset() on the first
variable but I cannot seem to track down why this wasn't implemented
in the final patch.

I'm merely looking for counter-arguments as to why an implicit
isset/isempty should not be performed when the first argument is
indeed a variable and not an expr. The only counter-argument (If this
can even be considered remotely related to an argument) is that having
an implicit isset() would return the boolean value of the check. See
in the common misconceptions of ifsetor on the wiki [1]

I am not trying to revive ifsetor() because I believe this is an
amazingly ugly language construct and I don't think it has an actual
place in PHP however, implicitly performing the ifestor check on
"variable"s and not "expr" could greatly improve it's usability I
believe.

Anyone has notes about the arguments against the implicit check at the
Chicago Round-Table meeting?

Thanks,

[1] Ifsetor cached wiki rfc:
http://webcache.googleusercontent.com/search?q=cache:jKrV2u7jeokJ:wiki.php.net/rfc/ifsetor+php+ifsetor+patch&cd=1&hl=en&ct=clnk&gl=us&client=firefox-a&source=www.google.com

-- 
David Coallier

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

Reply via email to