dmitry Mon, 17 Aug 2009 07:40:18 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=287396
Log: Fixed bug #49269 (Ternary operator fails on Iterator object when used inside foreach declaration). (Etienne, Dmitry) Bug: http://bugs.php.net/49269 (Assigned) Ternary operator fails on Iterator object when used inside foreach declaration Changed paths: U php/php-src/branches/PHP_5_2/NEWS A php/php-src/branches/PHP_5_2/Zend/tests/bug49269.phpt U php/php-src/branches/PHP_5_2/Zend/zend_vm_def.h U php/php-src/branches/PHP_5_2/Zend/zend_vm_execute.h Modified: php/php-src/branches/PHP_5_2/NEWS =================================================================== --- php/php-src/branches/PHP_5_2/NEWS 2009-08-17 07:15:43 UTC (rev 287395) +++ php/php-src/branches/PHP_5_2/NEWS 2009-08-17 07:40:18 UTC (rev 287396) @@ -1,6 +1,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2009, PHP 5.2.11 +- Fixed bug #49269 (Ternary operator fails on Iterator object when used inside + foreach declaration). (Etienne, Dmitry) + - Added missing sanity checks around exif processing (Ilia) 13 Aug 2009, PHP 5.2.11RC1 Added: php/php-src/branches/PHP_5_2/Zend/tests/bug49269.phpt =================================================================== --- php/php-src/branches/PHP_5_2/Zend/tests/bug49269.phpt (rev 0) +++ php/php-src/branches/PHP_5_2/Zend/tests/bug49269.phpt 2009-08-17 07:40:18 UTC (rev 287396) @@ -0,0 +1,26 @@ +--TEST-- +Bug #49269 (Ternary operator fails on Iterator object when used inside foreach declaration). +--FILE-- +<?php +class TestObject implements Iterator +{ + public $n = 0; + function valid() + { + return ($this->n < 3); + } + function current() {return $this->n;} + function next() {$this->n++;} + function key() { } + function rewind() {$this->n = 0;} +} + + +$array_object = new TestObject(); + +foreach ((true ? $array_object : $array_object) as $item) echo "$item\n"; +?> +--EXPECT-- +0 +1 +2 Modified: php/php-src/branches/PHP_5_2/Zend/zend_vm_def.h =================================================================== --- php/php-src/branches/PHP_5_2/Zend/zend_vm_def.h 2009-08-17 07:15:43 UTC (rev 287395) +++ php/php-src/branches/PHP_5_2/Zend/zend_vm_def.h 2009-08-17 07:40:18 UTC (rev 287396) @@ -3196,15 +3196,22 @@ ALLOC_ZVAL(tmp); INIT_PZVAL_COPY(tmp, array_ptr); array_ptr = tmp; + if (Z_TYPE_P(array_ptr) == IS_OBJECT) { + ce = Z_OBJCE_P(array_ptr); + if (ce && ce->get_iterator) { + array_ptr->refcount--; + } + } } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); if (!ce || !ce->get_iterator) { array_ptr->refcount++; } } else { - if ((OP1_TYPE == IS_CV || OP1_TYPE == IS_VAR) && + if (OP1_TYPE == IS_CONST || + ((OP1_TYPE == IS_CV || OP1_TYPE == IS_VAR) && !array_ptr->is_ref && - array_ptr->refcount > 1) { + array_ptr->refcount > 1)) { zval *tmp; ALLOC_ZVAL(tmp); @@ -3217,7 +3224,7 @@ } } - if (OP1_TYPE != IS_TMP_VAR && ce && ce->get_iterator) { + if (ce && ce->get_iterator) { iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { Modified: php/php-src/branches/PHP_5_2/Zend/zend_vm_execute.h =================================================================== --- php/php-src/branches/PHP_5_2/Zend/zend_vm_execute.h 2009-08-17 07:15:43 UTC (rev 287395) +++ php/php-src/branches/PHP_5_2/Zend/zend_vm_execute.h 2009-08-17 07:40:18 UTC (rev 287396) @@ -2230,15 +2230,22 @@ ALLOC_ZVAL(tmp); INIT_PZVAL_COPY(tmp, array_ptr); array_ptr = tmp; + if (Z_TYPE_P(array_ptr) == IS_OBJECT) { + ce = Z_OBJCE_P(array_ptr); + if (ce && ce->get_iterator) { + array_ptr->refcount--; + } + } } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); if (!ce || !ce->get_iterator) { array_ptr->refcount++; } } else { - if ((IS_CONST == IS_CV || IS_CONST == IS_VAR) && + if (IS_CONST == IS_CONST || + ((IS_CONST == IS_CV || IS_CONST == IS_VAR) && !array_ptr->is_ref && - array_ptr->refcount > 1) { + array_ptr->refcount > 1)) { zval *tmp; ALLOC_ZVAL(tmp); @@ -2251,7 +2258,7 @@ } } - if (IS_CONST != IS_TMP_VAR && ce && ce->get_iterator) { + if (ce && ce->get_iterator) { iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { @@ -4805,15 +4812,22 @@ ALLOC_ZVAL(tmp); INIT_PZVAL_COPY(tmp, array_ptr); array_ptr = tmp; + if (Z_TYPE_P(array_ptr) == IS_OBJECT) { + ce = Z_OBJCE_P(array_ptr); + if (ce && ce->get_iterator) { + array_ptr->refcount--; + } + } } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); if (!ce || !ce->get_iterator) { array_ptr->refcount++; } } else { - if ((IS_TMP_VAR == IS_CV || IS_TMP_VAR == IS_VAR) && + if (IS_TMP_VAR == IS_CONST || + ((IS_TMP_VAR == IS_CV || IS_TMP_VAR == IS_VAR) && !array_ptr->is_ref && - array_ptr->refcount > 1) { + array_ptr->refcount > 1)) { zval *tmp; ALLOC_ZVAL(tmp); @@ -4826,7 +4840,7 @@ } } - if (IS_TMP_VAR != IS_TMP_VAR && ce && ce->get_iterator) { + if (ce && ce->get_iterator) { iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { @@ -7954,15 +7968,22 @@ ALLOC_ZVAL(tmp); INIT_PZVAL_COPY(tmp, array_ptr); array_ptr = tmp; + if (Z_TYPE_P(array_ptr) == IS_OBJECT) { + ce = Z_OBJCE_P(array_ptr); + if (ce && ce->get_iterator) { + array_ptr->refcount--; + } + } } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); if (!ce || !ce->get_iterator) { array_ptr->refcount++; } } else { - if ((IS_VAR == IS_CV || IS_VAR == IS_VAR) && + if (IS_VAR == IS_CONST || + ((IS_VAR == IS_CV || IS_VAR == IS_VAR) && !array_ptr->is_ref && - array_ptr->refcount > 1) { + array_ptr->refcount > 1)) { zval *tmp; ALLOC_ZVAL(tmp); @@ -7975,7 +7996,7 @@ } } - if (IS_VAR != IS_TMP_VAR && ce && ce->get_iterator) { + if (ce && ce->get_iterator) { iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { @@ -20364,15 +20385,22 @@ ALLOC_ZVAL(tmp); INIT_PZVAL_COPY(tmp, array_ptr); array_ptr = tmp; + if (Z_TYPE_P(array_ptr) == IS_OBJECT) { + ce = Z_OBJCE_P(array_ptr); + if (ce && ce->get_iterator) { + array_ptr->refcount--; + } + } } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); if (!ce || !ce->get_iterator) { array_ptr->refcount++; } } else { - if ((IS_CV == IS_CV || IS_CV == IS_VAR) && + if (IS_CV == IS_CONST || + ((IS_CV == IS_CV || IS_CV == IS_VAR) && !array_ptr->is_ref && - array_ptr->refcount > 1) { + array_ptr->refcount > 1)) { zval *tmp; ALLOC_ZVAL(tmp); @@ -20385,7 +20413,7 @@ } } - if (IS_CV != IS_TMP_VAR && ce && ce->get_iterator) { + if (ce && ce->get_iterator) { iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php