|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67446 Add built-in function for combining isset() with value retrieval
Submitted: 2014-06-15 03:57 UTC Modified: 2014-06-15 09:42 UTC
From: nate at frickenate dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: nate at frickenate dot com
New email:
PHP Version: OS:


 [2014-06-15 03:57 UTC] nate at frickenate dot com
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:

// 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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-15 09:42 UTC]
-Status: Open +Status: Not a bug
 [2014-06-15 09:42 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

there were extensive discussions about this in the past. All ml threads should be linked here:
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 02:03:37 2021 UTC