Re: com php-src: Fixed bug #73686 (Adding settype()ed values to ArrayObject results in references): NEWS ext/spl/spl_array.c
ext/spl/tests/bug73686.phpt
| From: | Xinchen Hui | Date: | Fri, 09 Dec 2016 08:14:16 +0000 |
| Subject: | Re: com php-src: Fixed bug #73686 (Adding settype()ed values to ArrayObject results in references): NEWS ext/spl/spl_array.c ext/spl/tests/bug73686.phpt |
||
| References: | 1 2 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-96276@lists.php.net to get a copy of this message | ||
Hey:
On Fri, Dec 9, 2016 at 4:06 PM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Fri, Dec 9, 2016 at 4:41 AM, Xinchen Hui <laruence@php.net> wrote:
>
>> Commit: 68bdd6d0182efb58b975ce7057ea895e1de46697
>> Author: Xinchen Hui <laruence@gmail.com> Fri, 9 Dec 2016
>> 11:41:08 +0800
>> Parents: 8250b3fca18efd310769c40c3e578fd40df6428b
>> Branches: PHP-7.1 master
>>
>> Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=68bdd6dlÐ
>> ¹;J=h=´Ã!í@Ò
>> 0182efb58b975ce7057ea895e1de46697
>>
>> Log:
>> Fixed bug #73686 (Adding settype()ed values to ArrayObject results in
>> references)
>>
>> Bugs:
>> https://bugs.php.net/73686
>>
>> Changed paths:
>> M NEWS
>> M ext/spl/spl_array.c
>> A ext/spl/tests/bug73686.phpt
>>
>>
>> Diff:
>> diff --git a/NEWS b/NEWS
>> index 127bffe..66791ff 100644
>> --- a/NEWS
>> +++ b/NEWS
>> @@ -15,6 +15,10 @@ PHP
>> NEWS
>> . Fixed bug #72931 (PDO_FIREBIRD with Firebird 3.0 not work on
>> returning
>> statement). (Dorin Marcoci)
>>
>> +- SPL:
>> + . Fixed bug #73686 (Adding settype()ed values to ArrayObject results in
>> + references). (Laruence)
>> +
>> 01 Dec 2016, PHP 7.1.0
>>
>> - Core:
>> diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
>> index bddf64e..d3fbb95 100644
>> --- a/ext/spl/spl_array.c
>> +++ b/ext/spl/spl_array.c
>> @@ -473,6 +473,11 @@ static void spl_array_write_dimension_ex(int
>> check_inherited, zval *object, zval
>> return;
>> }
>>
>> + if (UNEXPECTED(Z_ISREF_P(value) &&
>> + Z_REFCOUNTED_P(value) == 1)) {
>> + ZVAL_UNREF(value);
>> + }
>>
>
> Shouldn't this simply DEREF? $a[$b] = $c should not keep $c as a reference
> even if it has refcount > 1.
>
> I'm also wondering if it wouldn't be better to add this back into
> ASSIGN_DIM? Otherwise all write_dimension handlers will have to add it.
>
ASSIGN_DIM already take care of array case, this should be only write_dim
case, but yes, it should be done in some place like assing_to_object.
I will take care of it, thanks
>
> Nikita
>
>
>> +
>> if (Z_REFCOUNTED_P(value)) {
>> Z_ADDREF_P(value);
>> }
>> diff --git a/ext/spl/tests/bug73686.phpt b/ext/spl/tests/bug73686.phpt
>> new file mode 100644
>> index 0000000..ae9a59c
>> --- /dev/null
>> +++ b/ext/spl/tests/bug73686.phpt
>> @@ -0,0 +1,45 @@
>> +--TEST--
>> +Bug #73686 (Adding settype()ed values to ArrayObject results in
>> references)
>> +--FILE--
>> +<?php
>> +
>> +$ao = new ArrayObject;
>> +
>> +foreach ([1, 2, 3] as $i => $var)
>> +{
>> + settype($var, 'string');
>> + $ao[$i] = $var;
>> +}
>> +var_dump($ao);
>> +
>> +$ao = new ArrayObject;
>> +
>> +foreach ([1, 2, 3] as $i => $var)
>> +{
>> + $ao[$i] = &$var;
>> +}
>> +var_dump($ao);
>> +?>
>> +--EXPECTF--
>> +object(ArrayObject)#%d (1) {
>> + ["storage":"ArrayObject":private]=>
>> + array(3) {
>> + [0]=>
>> + string(1) "1"
>> + [1]=>
>> + string(1) "2"
>> + [2]=>
>> + string(1) "3"
>> + }
>> +}
>> +object(ArrayObject)#%d (1) {
>> + ["storage":"ArrayObject":private]=>
>> + array(3) {
>> + [0]=>
>> + &int(3)
>> + [1]=>
>> + &int(3)
>> + [2]=>
>> + &int(3)
>> + }
>> +}
>>
>>
>> --
>> PHP CVS Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
--
Xinchen Hui
@Laruence
http://www.laruence.com/