|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-06-15 09:42 UTC] fa@php.net
-Status: Open
+Status: Not a bug
[2014-06-15 09:42 UTC] fa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
Description: ------------ The frequency at which an isset() call against an index of an array is immediately followed by retrieving the value at that index is extremely common. It would allow for much cleaner code if there were a built-in mechanism for combining these 2 operations into one, eliminating the need to type of the full array notation twice. Test script: --------------- <?php // code like this is commonly written; duplication of the // item $array['foo']['bar']['baz'] is extremely annoying: $value = isset($array['foo']['bar']['baz']) ? $array['foo']['bar']['baz'] : 'default'; // some people avoid this by (ugh!) using @ to skip the undefined index notice: if (($value = @$array['foo']['bar']['baz']) === null) { $value = 'default'; } // what we should really have (though with a better name, not sure what): $value = iisset($array['foo']['bar']['baz'], 'default'); // this can already be implemented without risk of a notice in userland: function iisset(&$var, $default = null) { return isset($var) ? $var : $default; } // but a php core replacement would make it universal and take less overhead