#50423 [Bgs]: Numerical keys casted as strings in arrays, when converting from object
ID: 50423 User updated by: anton at zebooka dot com Reported By: anton at zebooka dot com Status: Bogus Bug Type: Arrays related Operating System: Ubuntu 9.10 PHP Version: 5.2.11 New Comment: sorry, "throw" == "through" Previous Comments: [2009-12-09 17:38:31] anton at zebooka dot com Oh, hell. I know what is written in documentation. But this is clearly a bug. Why can't you open console, type "php -a" and test it your self??? For unbelievers: php > $o = new stdClass(); php > $o->{123} = 456; php > echo $o->{123}; 456 So object HAS!!! numerical properties. php > var_dump($o); object(stdClass)#1 (1) { ["123"]=> int(456) } php > var_dump($a); array(1) { ["123"]=> int(456) } php > error_reporting(-1); php > var_dump($a[123]); Notice: Undefined offset: 123 in php shell code on line 1 NULL There is still no bug??? Are you kidding? PHP team should either disable assigning properties with numberical names to objects (throw ->{} syntax and with (object) cast), or convert objects to arrays and arrays to objects normally, without such bells and candies. :) [2009-12-09 12:16:31] j...@php.net "If an object is converted to an array , the result is an array whose elements are the object 's properties. The keys are the member variable names, with a few notable exceptions: integer properties are unaccessible;" And this is exactly what happens. No bug here. [2009-12-09 09:47:48] johan...@php.net sorry misread it ------------ [2009-12-09 09:45:17] anton at zebooka dot com Yes, I can't. But I have!!! Look closer. Expected result is, when I convert object with numerially named properties, to get array with int keys. But instead I get an array with string numerical keys [2009-12-09 09:41:15] johan...@php.net 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 can\'t have array keys with numeric strings as key. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/50423 -- Edit this bug report at http://bugs.php.net/?id=50423&edit=1
#50423 [Bgs]: Numerical keys casted as strings in arrays, when converting from object
ID: 50423 User updated by: anton at zebooka dot com Reported By: anton at zebooka dot com Status: Bogus Bug Type: Arrays related Operating System: Ubuntu 9.10 PHP Version: 5.2.11 New Comment: Oh, hell. I know what is written in documentation. But this is clearly a bug. Why can't you open console, type "php -a" and test it your self??? For unbelievers: php > $o = new stdClass(); php > $o->{123} = 456; php > echo $o->{123}; 456 So object HAS!!! numerical properties. php > var_dump($o); object(stdClass)#1 (1) { ["123"]=> int(456) } php > var_dump($a); array(1) { ["123"]=> int(456) } php > error_reporting(-1); php > var_dump($a[123]); Notice: Undefined offset: 123 in php shell code on line 1 NULL There is still no bug??? Are you kidding? PHP team should either disable assigning properties with numberical names to objects (throw ->{} syntax and with (object) cast), or convert objects to arrays and arrays to objects normally, without such bells and candies. :) Previous Comments: [2009-12-09 12:16:31] j...@php.net "If an object is converted to an array , the result is an array whose elements are the object 's properties. The keys are the member variable names, with a few notable exceptions: integer properties are unaccessible;" And this is exactly what happens. No bug here. [2009-12-09 09:47:48] johan...@php.net sorry misread it -------------------- [2009-12-09 09:45:17] anton at zebooka dot com Yes, I can't. But I have!!! Look closer. Expected result is, when I convert object with numerially named properties, to get array with int keys. But instead I get an array with string numerical keys [2009-12-09 09:41:15] johan...@php.net 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 can\'t have array keys with numeric strings as key. ---------------- [2009-12-09 09:36:10] anton at zebooka dot com Again, if you then do echo $a[0]; you'll get 123 instead of 456. Even if you call arsort($a); the result will be the same - 123. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/50423 -- Edit this bug report at http://bugs.php.net/?id=50423&edit=1
#50423 [Bgs]: Numerical keys casted as strings in arrays, when converting from object
ID: 50423 User updated by: anton at zebooka dot com Reported By: anton at zebooka dot com Status: Bogus Bug Type: Arrays related Operating System: Ubuntu 9.10 PHP Version: 5.2.11 New Comment: Yes, I can't. But I have!!! Look closer. Expected result is, when I convert object with numerially named properties, to get array with int keys. But instead I get an array with string numerical keys Previous Comments: [2009-12-09 09:41:15] johan...@php.net 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 can\'t have array keys with numeric strings as key. [2009-12-09 09:36:10] anton at zebooka dot com Again, if you then do echo $a[0]; you'll get 123 instead of 456. Even if you call arsort($a); the result will be the same - 123. [2009-12-09 09:33:43] anton at zebooka dot com Description: As mentioned in documentation, array items can have either string or int. However keys that are numerical strings are converted to int. This is how to create an array with item, which key is string, while it is a number. Reproduce code: --- $a = array(123); $o = (object) $a; $o->{0} = 456; $a = (array) $o; var_dump($a); Expected result: array(2) { [0]=> int(456) } Actual result: -- array(2) { [0]=> int(123) ["0"]=> int(456) } -- Edit this bug report at http://bugs.php.net/?id=50423&edit=1
#50423 [Opn]: Numerical keys casted as strings in arrays, when converting from object
ID: 50423 User updated by: anton at zebooka dot com Reported By: anton at zebooka dot com Status: Open Bug Type: Arrays related Operating System: Ubuntu 9.10 PHP Version: 5.2.11 New Comment: Again, if you then do echo $a[0]; you'll get 123 instead of 456. Even if you call arsort($a); the result will be the same - 123. Previous Comments: [2009-12-09 09:33:43] anton at zebooka dot com Description: As mentioned in documentation, array items can have either string or int. However keys that are numerical strings are converted to int. This is how to create an array with item, which key is string, while it is a number. Reproduce code: --- $a = array(123); $o = (object) $a; $o->{0} = 456; $a = (array) $o; var_dump($a); Expected result: array(2) { [0]=> int(456) } Actual result: -- array(2) { [0]=> int(123) ["0"]=> int(456) } -- Edit this bug report at http://bugs.php.net/?id=50423&edit=1
#50423 [NEW]: Numerical keys casted as strings in arrays, when converting from object
From: anton at zebooka dot com Operating system: Ubuntu 9.10 PHP version: 5.2.11 PHP Bug Type: Arrays related Bug description: Numerical keys casted as strings in arrays, when converting from object Description: As mentioned in documentation, array items can have either string or int. However keys that are numerical strings are converted to int. This is how to create an array with item, which key is string, while it is a number. Reproduce code: --- $a = array(123); $o = (object) $a; $o->{0} = 456; $a = (array) $o; var_dump($a); Expected result: array(2) { [0]=> int(456) } Actual result: -- array(2) { [0]=> int(123) ["0"]=> int(456) } -- Edit bug report at http://bugs.php.net/?id=50423&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50423&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50423&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50423&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50423&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50423&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50423&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50423&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50423&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50423&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50423&r=support Expected behavior: http://bugs.php.net/fix.php?id=50423&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50423&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50423&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50423&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50423&r=php4 Daylight Savings:http://bugs.php.net/fix.php?id=50423&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50423&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50423&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50423&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50423&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50423&r=mysqlcfg