php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40216 Test showing Bug 39449 isn't totally fixed yet
Submitted: 2007-01-24 05:39 UTC Modified: 2007-01-24 13:49 UTC
From: scott dot pascoe at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.1RC3 OS: Windows XP
Private report: No CVE-ID: None
 [2007-01-24 05:39 UTC] scott dot pascoe at gmail dot com
Description:
------------
The reproduce code is in a test format.  In php 5.1.4, it outputs the expected output, it does not in 5.2.0, or does it in the 5.2.1 snapshot from today.  It was reported to be fixed on 2007-01-10, but isn't yet.  The symfony framework depends upon this capability.

Reproduce code:
---------------
--TEST--
 Bug #39449 (Behavior changed from php 5.1.4 to 5.2.0)
--FILE--
<?php
// hacked for this test
$ns = 'test';

class ParameterHolder {
  protected $parameters = array();
  public function & get($name) {
      return & $this->parameters[$ns][$name];
  }
  public function setByRef($name, & $value) {
    if (!isset($this->parameters[$ns]))
      $this->parameters[$ns] = array();
    $this->parameters[$ns][$name] =& $value;
  }
}

class Bug39449 {
  protected
    $varHolder = null;
  public function __construct() {
    $this->varHolder = new ParameterHolder();
  }
  public function getVarHolder() {
    return $this->varHolder;
  }
  public function __set($key, $value) {
    return $this->varHolder->setByRef($key, $value);
  }
  public function __get($key) {
    return $this->varHolder->get($key);
  }
}

$b = new Bug39449();
$b->foo = Array();
$b->foo[0] = 'bar';

foreach  ($b->foo as $k => $v) {
  echo "$k => $v\n";
}
?>
--EXPECT--
0 => bar




Expected result:
----------------
0 => bar

Actual result:
--------------
[nothing]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-24 09:27 UTC] tony2001@php.net
This code does not work at all:

Parse error: syntax error, unexpected '&' in /tmp/4.php on line 8
Notice: Undefined variable: ns in /tmp/4.php on line 11
 [2007-01-24 13:24 UTC] scott dot pascoe at gmail dot com
Sorry, I hacked too much out of it to make it be very small.  Replacing the '$ns' references with "'test'" will make it work.

Scott
 [2007-01-24 13:49 UTC] tony2001@php.net
<?php
class ParameterHolder {
  protected $parameters = array();
  public function &get($name) {
      return $this->parameters['test'][$name];
  }
  public function setByRef($name, & $value) {
    if (!isset($this->parameters['test']))
      $this->parameters['test'] = array();
    $this->parameters['test'][$name] =& $value;
  }
}

class Bug39449 {
  protected
    $varHolder = null;
  public function __construct() {
    $this->varHolder = new ParameterHolder();
  }
  public function getVarHolder() {
    return $this->varHolder;
  }
  public function __set($key, $value) {
    return $this->varHolder->setByRef($key, $value);
  }
  public function &__get($key) { /* NB */
    return $this->varHolder->get($key);
  }
}

$b = new Bug39449();
$b->foo = Array();
$b->foo[0] = 'bar';

foreach  ($b->foo as $k => $v) {
  echo "$k => $v\n";
}
?>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 17:01:27 2025 UTC