ID: 11092
Updated by: sbergmann
Reported By: [EMAIL PROTECTED]
Status: Open
Bug Type: Scripting Engine problem
Operating system: 
PHP Version: 4.0.5
Assigned To: 
Comments:

Just noticed: It works as expected when I replace

  $a = $b->add_a();

with

  $a =& $b->add_a();

But this is not the syntax I was thinking of for my class. The user, which probably 
doesn't know of the class's internals, now has always use the =& assignment operator. 
This is definetly error-prone.


Previous Comments:
---------------------------------------------------------------------------

[2001-05-24 13:04:25] [EMAIL PROTECTED]
There seems to be a problem with objects returned from class methods by reference:

<?php
class a {
  var $data;

  function add_data($data) {
    $this->data[] = $data;
  }
}

class b {
  var $a;

  function &add_a() {
    $this->a = new a;
    return $this->a;
  }

  function dump() {
    print_r($this->a->data);
  }
}

$b = new b;
$a = $b->add_a();
$a->add_data('test');    // works not
$b->a->add_data('test'); // works
$b->dump();
?>


---------------------------------------------------------------------------



ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=11092&edit=2


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to