|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-11-09 13:39 UTC] serovov at gmail dot com
[2008-11-09 14:36 UTC] felipe@php.net
[2008-11-09 14:36 UTC] felipe@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 20:00:01 2025 UTC |
Description: ------------ When object has numeric named vars, and we cast this object to array. we have a problem with isset() checks; PS. if is not a bug, please, explain why. Reproduce code: --------------- <?php class buggy { public function __construct(array $data) { foreach ($data as $key => $value) { $this->$key = $value; } } } function test_buggy($buggy) { $kbuggy = array_keys($buggy); var_dump( $buggy, $kbuggy, isset($buggy[current($kbuggy)]), isset($buggy[$kbuggy[0]]), isset($buggy[$kbuggy[1]]), isset($buggy[$kbuggy[2]]) ); } $array = array( 'a', 'b', 'c', ); $buggy = new buggy($array); $buggy = (array) $buggy; echo "Test #1: "; test_buggy($buggy); echo "Test #2: "; $buggy = unserialize(serialize($buggy)); test_buggy($buggy); ?> Expected result: ---------------- Test #1: array '0' => string 'a' (length=1) '1' => string 'b' (length=1) '2' => string 'c' (length=1) array 0 => string '0' (length=1) 1 => string '1' (length=1) 2 => string '2' (length=1) boolean false boolean false boolean false boolean false Test #2: array 0 => string 'a' (length=1) 1 => string 'b' (length=1) 2 => string 'c' (length=1) array 0 => int 0 1 => int 1 2 => int 2 boolean true boolean true boolean true boolean true Actual result: -------------- Test #1: array 0 => string 'a' (length=1) 1 => string 'b' (length=1) 2 => string 'c' (length=1) array 0 => int 0 1 => int 1 2 => int 2 boolean true boolean true boolean true boolean true Test #2: array 0 => string 'a' (length=1) 1 => string 'b' (length=1) 2 => string 'c' (length=1) array 0 => int 0 1 => int 1 2 => int 2 boolean true boolean true boolean true boolean true