php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73686 Adding settype()ed values to ArrayObject results in references.
Submitted: 2016-12-08 13:37 UTC Modified: 2016-12-08 19:24 UTC
From: arjen at parse dot nl Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.1.0 OS: All
Private report: No CVE-ID: None
 [2016-12-08 13:37 UTC] arjen at parse dot nl
Description:
------------
Found at https://twitter.com/kozzi11/status/806828728890380288

https://3v4l.org/suHQh

Removing the settype() call produces the expected output.

Test script:
---------------
<?php

$ao = new ArrayObject;

foreach ([1, 2, 3] as $i => $var)
{
    settype($var, 'string');
    $ao[$i] = $var;
}

var_dump($ao);

Expected result:
----------------
Output for 5.6.0 - 5.6.28, hhvm-3.12.0 - 3.13.2, 7.0.0 - 7.0.14

object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "2"
    [2]=>
    string(1) "3"
  }
}

Actual result:
--------------
Output for 7.1.0

object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(3) {
    [0]=>
    &string(1) "3"
    [1]=>
    &string(1) "3"
    [2]=>
    &string(1) "3"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-08 19:24 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: dmitry
 [2016-12-08 19:24 UTC] cmb@php.net
Thanks for properly reporting this issue here, Arjen!

Apparently, this bug has been introduced with commit eaf489ac[1]. Dmitry, could you please have a look at this issue?

[1] <http://git.php.net/?p=php-src.git;a=commit;h=eaf489ac>
 [2016-12-09 03:42 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=68bdd6d0182efb58b975ce7057ea895e1de46697
Log: Fixed bug #73686 (Adding settype()ed values to ArrayObject results in references)
 [2016-12-09 03:42 UTC] laruence@php.net
-Status: Verified +Status: Closed
 [2016-12-09 08:43 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4589386026dbf15d980ba0c7c92dc587cead15e8
Log: Refix bug #73686
 [2016-12-09 14:31 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6812721ef2c52ca7f518c6664a1933ffb58b3715
Log: Revert &quot;Refix bug #73686&quot;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC