Bug #69799 [NEW]: Integer as object property. Malformed array.
| From: | miloslav dot hula at gmail dot com | Date: | Thu, 11 Jun 2015 13:37:54 +0000 |
| Subject: | Bug #69799 [NEW]: Integer as object property. Malformed array. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193328@lists.php.net to get a copy of this message | ||
From: miloslav dot hula at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Integer as object property. Malformed array.
Description:
------------
When integer used as object's property name, conversion to array by
(array) makes normally integer array keys as string. In result, isset()
and array_key_exists() doesn't work on malformed array.
Test script:
---------------
<?php
# available on http://3v4l.org/ambbi
class ArrayHash extends \stdClass
{
public static function from(array $arr)
{
$obj = new static;
foreach ($arr as $key => $value) {
$obj->$key = $value;
}
return $obj;
}
}
$one = array('abcdef' => 'xxx', '102787' => 'yyy');
$two = (array) ArrayHash::from($one);
echo "# One\n";
var_dump($one);
var_dump(isset($one['abcdef']));
var_dump(array_key_exists('abcdef', $one));
var_dump(isset($one[102787]));
var_dump(array_key_exists(102787, $one));
var_dump(isset($one['102787']));
var_dump(array_key_exists('102787', $one));
echo "\n\n";
echo "# Two\n";
var_dump($two);
var_dump(isset($two['abcdef']));
var_dump(array_key_exists('abcdef', $two));
var_dump(isset($two[102787]));
var_dump(array_key_exists(102787, $two));
var_dump(isset($two['102787']));
var_dump(array_key_exists('102787', $two));
echo "\n\n";
Expected result:
----------------
# One
array(2) {
["abcdef"]=>
string(3) "xxx"
[102787]=>
string(3) "yyy"
}
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
# Two
array(2) {
["abcdef"]=>
string(3) "xxx"
["102787"]=>
string(3) "yyy"
}
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Actual result:
--------------
# One
array(2) {
["abcdef"]=>
string(3) "xxx"
[102787]=>
string(3) "yyy"
}
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
# Two
array(2) {
["abcdef"]=>
string(3) "xxx"
["102787"]=>
string(3) "yyy"
}
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=69799&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69799&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69799&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69799&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69799&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69799&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69799&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69799&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69799&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69799&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69799&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69799&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69799&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69799&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69799&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69799&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69799&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69799&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69799&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69799&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69799&r=mysqlcfg