Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11998 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 171 invoked by uid 1010); 8 Aug 2004 02:07:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 146 invoked from network); 8 Aug 2004 02:07:22 -0000 Received: from unknown (HELO took.shire) (68.122.184.4) by pb1.pair.com with SMTP; 8 Aug 2004 02:07:22 -0000 Received: (qmail 35052 invoked by uid 1001); 8 Aug 2004 02:23:53 -0000 Date: Sun, 8 Aug 2004 02:23:53 +0000 To: internals@lists.php.net Message-ID: <20040808022353.GG6522@bagend.shire> Mail-Followup-To: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Subject: objects passed as reference in php5 From: curt@php.net (Curt Zirzow) I'm trying to document how objects are passed to functions in php5, but am running into some troubles. In the code below the object appears to be a reference but when the original object is destoyed it still somehow exists. Can someone explain how this is? I was going to report a bug on this but using the traditional &$obj usage it works perfectly fine. class Test { public $object = null; public $object1 = null; function SetVarVal($obj) { $this->object = $obj; } function SetVarRef(&$obj) { $this->object1 = &$obj; } } $obj1 = new StdClass(); $obj2 = new Test(); $obj2->SetVarVal($obj1); $obj2->SetVarRef($obj1); $obj1->foo = 'test'; /* show how obj1's is a ref */ $obj1 = null; /* destroy object */ var_dump($obj2->object); /* still has object with ->foo */ var_dump($obj2->object1); /* NULL */ Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid!