Bug #67300 [NEW]: Cast (object) array() ALLOWS to create property with empty name
| From: | vovan-ve at yandex dot ru | Date: | Mon, 19 May 2014 06:41:42 +0000 |
| Subject: | Bug #67300 [NEW]: Cast (object) array() ALLOWS to create property with empty name | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185853@lists.php.net to get a copy of this message | ||
From: vovan-ve at yandex dot ru
Operating system:
PHP version: Irrelevant
Package: Class/Object related
Bug Type: Bug
Bug description:Cast (object) array() ALLOWS to create property with empty name
Description:
------------
Due to some reasons we are not allowed to create property with empty
name:
$object = new stdClass();
$object->{""} = 42;
// Fatal error: Cannot access empty property
Ok. But type-cast
(object) doesn't know about this restriction:
http://3v4l.org/IU3GW . This inconsistency cause some problems.
All PHP/5 versions affected including PHP/5.5 and PHP/5.6.0beta3:
Some features emits a notice, others aren't.
Some features interacts with empty property, others aren't.
(there are some different behaviours in very old versions)
Test script:
---------------
<?php
$object = (object) array(
"foo" => 42,
"" => 37,
"bar" => 19,
);
echo "+ object created:\n";
var_dump($object);
echo "\nenum properties:\n";
foreach ($object as $p => $v) {
var_dump($p);
}
echo "\nget_object_vars()\n";
var_dump(get_object_vars($object));
Expected result:
----------------
Fatal error: Cannot access empty property
(or an Exception should be better)
Actual result:
--------------
+ object created:
object(stdClass)#1 (3) {
["foo"]=>
int(42)
Notice: Illegal member variable name in ... on line 9
[""]=>
int(37)
["bar"]=>
int(19)
}
enum properties:
string(3) "foo"
Notice: Illegal member variable name in ... on line 12
string(3) "bar"
get_object_vars()
Notice: Illegal member variable name in ... on line 17
array(2) {
["foo"]=>
int(42)
["bar"]=>
int(19)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=67300&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67300&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67300&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67300&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67300&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67300&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67300&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67300&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67300&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67300&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67300&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67300&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67300&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67300&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67300&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67300&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67300&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67300&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67300&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67300&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67300&r=mysqlcfg