Bug #73700 [Opn->Dup]: Incosistent behavior when accessing scalars as an array
| From: | requinix@php.net | Date: | Fri, 09 Dec 2016 12:50:13 +0000 |
| Subject: | Bug #73700 [Opn->Dup]: Incosistent behavior when accessing scalars as an array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205878@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73700&edit=1
ID: 73700
Updated by: requinix@php.net
Reported by: onno dot marsman at gmail dot com
Summary: Incosistent behavior when accessing scalars as an
array
-Status: Open
+Status: Duplicate
Type: Bug
Package: Variables related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This is a known issue pending implementation.
https://wiki.php.net/rfc/notice-for-non-valid-array-container
Previous Comments:
------------------------------------------------------------------------
[2016-12-09 12:31:31] onno dot marsman at gmail dot com
Description:
------------
If you write an array index to a number, a "Cannot use a scalar value as an array" is
triggered. This is desired behavior.
In several other similar cases when treating a scalar as an array this warning is not triggered,
where this would be desired in my opinion. See test script for the examples.
Because a string is a scalar you would expect this warning to be also triggered when accessing a
string as an array, but of course this not desired, since accessing a string as an array is a
feature. Therefor the message of the warning "Cannot use a scalar value as an array" maybe
should be reconsidered.
Test script:
---------------
// The following case produces a "Cannot use a scalar value as an array" warning:
// 1. write as an array to a number
$a = 1;
$a[1] = 1;
// The following cases do not produce this warning:
// 2. write as an array to null
$a = null;
$a[1] = 1;
// 3. write as an array to false
$a = false;
$a[1] = 1;
// 4. read as an array from a number
$a = 1;
var_dump($a[1]);
// results in NULL
// 5. read as an array from null
$a = null;
var_dump($a[1]);
// results in NULL
// 6. read as an array from false
$a = false;
var_dump($a[1]);
// results in NULL
Expected result:
----------------
Get 6 warnings instead of just 1.
Actual result:
--------------
Only 1 warning.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73700&edit=1