php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32334 __set acts unexpected with variable variables
Submitted: 2005-03-16 13:29 UTC Modified: 2005-06-06 08:54 UTC
From: mk at peytz dot dk Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-04-04 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mk at peytz dot dk
New email:
PHP Version: OS:

 

 [2005-03-16 13:29 UTC] mk at peytz dot dk
Description:
------------
When setting variable variable values on a instance of a class with an overloading __set function changing another instance variable goes wrong.

(I'm reporting it for version 5.0.3 because the current cvs snapshot would not compile.)

Reproduce code:
---------------
http://dev.peytz.dk/~mk/setter.php
<?php
class Setter
{
    private $_fields = array(); // the data fields
    private $_changedFields = array(); // list of changed fields

    function __set($name, $value)
    {
        // set value
        $this->_fields[$name] = $value;
        // add to list of changed fields
        $this->_changedFields[] = $name;
    }
}
$foo = new Setter;
$foo->a = 1;
$var = "b";
$foo->$var = 2;
var_export($foo);
?>

Expected result:
----------------
class Setter {
  private $_fields = 
  array (
    'a' => 1,
    'b' => 2,
  );
  private $_changedFields = 
  array (
    0 => 'a',
    1 => 'b',
  );
}

Actual result:
--------------
class Setter {
  private $_fields = 
  array (
    'a' => 1,
    'b' => 2,
  );
  private $_changedFields = 
  array (
    0 => 'a',
    1 => '???',
  );
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-19 12:38 UTC] tony2001@php.net
Can't reproduce *your* behaviour with latest 5.0.x & 5.1 CVS.
But some issue really exists, as I get NULL instead of 'b' with both branches.

 [2005-04-01 13:51 UTC] mk at peytz dot dk
Still present in 5.0.4 but now only with NULL values.
 [2005-04-04 00:00 UTC] sniper@php.net
Changed the var_export() -> var_dump() and got this with
latest CVS:

object(Setter)#1 (2) {
  ["_fields:private"]=>
  array(2) {
    ["a"]=>
    int(1)
    ["b"]=>
    int(2)
  }
  ["_changedFields:private"]=>
  array(2) {
    [0]=>
    string(1) "a"
    [1]=>
    &UNKNOWN:0
  }
}

 [2005-06-06 08:54 UTC] dmitry@php.net
This bug is already fixed in CVS HEAD and PHP_5_0.
See Zend/tests/object_handlers.phpt
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Mar 07 03:01:23 2021 UTC