Bug #61126 [Opn->Nab]: associative array syntax
| From: | nikic@php.net | Date: | Sat, 18 Feb 2012 11:45:03 +0000 |
| Subject: | Bug #61126 [Opn->Nab]: associative array syntax | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167612@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61126&edit=1
ID: 61126
Updated by: nikic@php.net
Reported by: cornelius dot howl at gmail dot com
Summary: associative array syntax
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Any
PHP Version: 5.4.0RC7
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You access an undefined index so you obviously get a notice, nothing will change about that.
If you want, you can define a function like
function getWithDefault(&$var, $default = null) {
return isset($var) ? $var : $default;
}
$abc = getWithDefault($def['abc'], 'ghi');
Previous Comments:
------------------------------------------------------------------------
[2012-02-17 17:54:01] cornelius dot howl at gmail dot com
Description:
------------
When using undefined $args['method'] this should not throw an error, instead, it
should return undef or null.
In Perl or Ruby, Python, we usually write:
$value = $hash{key} || 'default value';
But in PHP, we have to write such code, that's such inefficient:
$value = isset($hash['key']) ? $hash['key'] : 'default';
Yes, we can use '@', but the '@' makes PHP runs more slower.
It will be better if we can have the following syntax:
$value = $hash['key'] || 'default value';
so that if you have multiple hashes:
$value = $hash['key'] || $hash2['key'] || $hash3['key'] ||
'last value';
then we don't have to write:
$value = isset($hash['key']) ? $hash['key'] : isset($hash2['key'])
?
$hash2['key'] : $hash2['key'] ........ # whatever
Thanks
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61126&edit=1