|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-29 10:46 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
Description: ------------ Recently I came across a bug in my work with Zend Framework linked with Smarty. In my investigation I found strange feature of PHP about creation new element in array if we assign by ref some undefined index from it (ZEND_FETCH_DIM_W implementation). For example: $a = array(); $b =& $a['test?]; After this code array $a will get new element indexed as ?test? and pointing to NULL. This is strange and I didn?t find documentation for this, but this is rather a feature than a bug. But I found situation in which above code return _different_ result, which is really bad and breaks Smarty plugins loading. This situation happened when we return undefined field in count function in Countable object. For example class Test implements Countable { public function count() { return $this->test; } } In my opinion calling count on such object (object of class Test) break global variable in Zend Engine named ?uninitialized_zval? and as a result new created elements point to int(0) instead of NULL Please make this feature more predictable Reproduce code: --------------- <?php class Test implements Countable { public function count() { return $this->some; } } $obj = new Test(); $a = array(); $b =& $a['test']; var_dump($a); $t = count($obj); $a = array(); $b =& $a['test']; var_dump($a); Expected result: ---------------- array(1) { ["test"]=> &NULL } array(1) { ["test"]=> &NULL } Actual result: -------------- array(1) { ["test"]=> &NULL } array(1) { ["test"]=> &int(0) }