From: Operating system: PHP version: 5.3.6 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Shorter or more eadable solution to get possibly undefined variables
Description: ------------ At the moment to read a possibly undefined variable without triggering an E_NOTICE you have to do something like this: echo isset($_REQUEST['foo']) ? $_REQUEST['foo'] : NULL; I would like to use a shorter version (or at least write the variable name only once) to get the code more clean. A solution could be to introduce a construct like: echo ifset($_REQUEST['foo']); The ifset() would do the same like the first example. In the comment to a similar feature request (http://bugs.php.net/bug.php?id=43236) it is recommended to use the new ternary ?: operator like: echo $_REQUEST['foo'] ?: NULL; However that is triggering an E_NOTICE too at the moment. I'm not sure if it would be a good idea, but maybe, as an alternative solution to the ifset() construct, the ?: operator could be enhanced to raise no E_NOTICE in such situations? Of course the solution in the first example is running and okay. So in the end we are talking about a "nice to have". However, because I see a lot of places where this could make code shorter and more readable I would really like to see such a function or enhancement. Test script: --------------- ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); echo $_REQUEST['foo']; echo $_REQUEST['foo'] ?: NULL; -- Edit bug report at http://bugs.php.net/bug.php?id=54738&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54738&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54738&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54738&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54738&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54738&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54738&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54738&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54738&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54738&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54738&r=support Expected behavior: http://bugs.php.net/fix.php?id=54738&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54738&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54738&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54738&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54738&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54738&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54738&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54738&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54738&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54738&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54738&r=mysqlcfg
