From: zyss at mail dot zp dot ua Operating system: All PHP version: 5.2.5 PHP Bug Type: Feature/Change Request Bug description: "if set" and "if not set" functions (ifset, ifnset)
Description: ------------ PHP programmers often need to check if certain variable is set when assigning its value to other variable or using it in expression. For example: $item_id = isset($_POST['item_id']) ? $_POST['item_id'] : null; which is quite unreadable. It would be much easier to write such things if there are function ifnset(mixed $value, mixed $alt) (If Not Set) which returns $value if $valus is set or $alt otherwise. Example above could be replaced with: $item_id = ifnset($_POST['item_id'], null); or, if another function is added - ifset - which returns null if its argument is not set or not defined: $item_id = ifset($_POST['item_id']); Similar function exists in MySQL (http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html#function_ifnull) which makes life much easier when working with MySQL. It is not possible to implement this function in PHP because when undefined or unset variable is passed as function argument PHP emits warning. Although warnings could be suppressed with @ it significantly slows down performance when such situation happens. Besides debugger catches all suppressed warnings anyway. Thanks. -- Edit bug report at http://bugs.php.net/?id=43236&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43236&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43236&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43236&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43236&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43236&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43236&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43236&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43236&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43236&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43236&r=support Expected behavior: http://bugs.php.net/fix.php?id=43236&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43236&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43236&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43236&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43236&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43236&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43236&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43236&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43236&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43236&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43236&r=mysqlcfg
