php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22443 Reference problem inside constructor
Submitted: 2003-02-26 11:27 UTC Modified: 2003-03-06 15:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: oracle16 at freemail dot hu Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.1 OS: Windows
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: oracle16 at freemail dot hu
New email:
PHP Version: OS:

 

 [2003-02-26 11:27 UTC] oracle16 at freemail dot hu
I have a problem when using two-way references.
The simplest case I could dig out:


<pre>

class B
{
  var $a;
  function B(& $a)
  {
    $this->a = & $a;
  }
}

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

$a = new A();

$a->x = "ax";

print $a->b->a->x;

<pre>

I think this should print out "ax". However it doesn't.

If I add the following line after constructing $a:

$a->b->a = &$a;

then it works, it prints out "ax".

Or, if I define A like this:

<pre>

class A
{
  var $b;
  function A()
  {
    $this->b = & new B($this);
  }
  function setBsA()
  {
    $this->b->a = & $this;
  }
}

</pre>

and call setBsA() after contructing, it still works.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-06 15:24 UTC] moriyoshi@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

[HINT] $a = &new A();

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 20:01:29 2024 UTC