|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-25 20:31 UTC] bobwei9 at hotmail dot com
Description: ------------ You can see here that once it's a string-index and once an int-index. But I don't suppose that this result is wanted? p.ex.: http://bobweinand.no-ip.org/php_test.php?simu%5Bang%5D%5B1%5D=79&simu%5Bver%5D%5B1%5D=&simu%5Bang%5D%5B2%5D=786&simu%5Bver%5D%5B2%5D=&simu%5Bang%5D%5B3%5D=&simu%5Bver%5D%5B3%5D=78786&simu%5Bang%5D%5B4%5D=&simu%5Bver%5D%5B4%5D=8&simu%5Bang%5D%5B5%5D=89&simu%5Bver%5D%5B5%5D=8&simu%5Bang%5D%5B6%5D=&simu%5Bver%5D%5B6%5D=445&simu%5Bang%5D%5B7%5D=&simu%5Bver%5D%5B7%5D=3&simu%5Bang%5D%5B8%5D=&simu%5Bver%5D%5B8%5D= Test script: --------------- http://bobweinand.no-ip.org/php_bug_test.php Expected result: ---------------- string(1) "1" string(1) "2" string(1) "3" string(1) "4" string(1) "5" string(1) "6" string(1) "7" string(1) "8" Array ( [0] => stdClass Object ( [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 ) [1] => stdClass Object ( [1] => [2] => [3] => 78786 [4] => 8 [5] => 8 [6] => 445 [7] => 3 [8] => ) ) Actual result: -------------- int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) string(1) "1" string(1) "2" string(1) "3" string(1) "4" string(1) "5" string(1) "6" string(1) "7" string(1) "8" Array ( [0] => stdClass Object ( [1] => 79 [2] => 786 [3] => [4] => [5] => 89 [6] => [7] => [8] => [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 ) [1] => stdClass Object ( [1] => [2] => [3] => 78786 [4] => 8 [5] => 8 [6] => 445 [7] => 3 [8] => [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 ) ) PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 06:00:01 2025 UTC |
expected result: string(1) "1" string(1) "2" string(1) "3" string(1) "4" string(1) "5" string(1) "6" string(1) "7" string(1) "8" Array ( [0] => stdClass Object ( [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 ) [1] => stdClass Object ( [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 ) )I don't understand this bug report. I see this in $_GET: Array ( [ang] => Array ( [1] => 79 [2] => 786 [3] => [4] => [5] => 89 [6] => [7] => [8] => ) [ver] => Array ( [1] => [2] => [3] => 78786 [4] => 8 [5] => 8 [6] => 445 [7] => 3 [8] => ) ) That looks correct to me.Yes, but this: for ($i=1;8 >= $i;$i++) { $ang->$i *= $ang_fak; $ver->$i *= $ver_fak; } creates a new index (string), and don't overwrite the old index (int), and also there are two indexes of the same value (but two different types int and string)Right, so your bug report is just a really obfuscated way of reporting this: $a = array(1=>'abc'); $b = (object)$a; $i=1; $b->$i = 'def'; var_dump($b); which shows the inherent side-effects of casting an array to an object indiscriminately. This is just how it works. You can kinda-sorta fake numeric properties if you try hard, but it is a bad idea. Fix your code to do: $a = array('1'=>'abc'); $b = new stdclass; foreach($a as $k=>$v) $b->$k = $v; $i=1; $b->$i = 'def'; var_dump($b); instead of expecting casting to do the right thing. Or if you know you are going to be using the array as an object, use string indices. Like a1, a2, a3..