php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33370 PHP does not create references to $this
Submitted: 2005-06-16 22:22 UTC Modified: 2005-06-16 22:25 UTC
From: borysf at wp dot pl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.4.0RC1 OS: Windows, Linux
Private report: No CVE-ID: None
 [2005-06-16 22:22 UTC] borysf at wp dot pl
Description:
------------
There is a bug in creating references (This problem does not exist in PHP5). If you have, for example, two classes and the first class creates second and passes itself as reference to second's constructor, reference is not being created. I've been trying to create this reference in many ways, but always with the same result - there is no reference, only a copy of class which was passed as reference.

Reproduce code:
---------------
class B {
  var $Parent;
  function B(&$parent) {
     $this->Parent = $parent;
     $this->Parent->Data = 'foo';
  }
}

class A {
   var $Data;
   var $B;
   function A() {
      $this->B = new B($this);
   }
}

$a = new A;
echo $a->Data;

Expected result:
----------------
echo should return 'foo', but returns nothing. In php5 it works properly. Note, that I have used the & operator in B's constructor to create a reference to A class.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-16 22:25 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You are creating the copy here:
     $this->Parent = $parent;

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 08:01:28 2024 UTC