Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13140 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67492 invoked by uid 1010); 4 Oct 2004 14:52:31 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 67445 invoked from network); 4 Oct 2004 14:52:30 -0000 Received: from unknown (HELO mail.internet-factory.de) (62.134.147.34) by pb1.pair.com with SMTP; 4 Oct 2004 14:52:30 -0000 Received: from pharao.lammfellpuschen.de (p508219E3.dip.t-dialin.net [80.130.25.227]) by mail.internet-factory.de (8.12.8/8.12.8) with SMTP id i94Eq3L4002730; Mon, 4 Oct 2004 16:52:04 +0200 Received: by pharao.lammfellpuschen.de (sSMTP sendmail emulation); Mon, 4 Oct 2004 16:52:03 +0200 Date: Mon, 4 Oct 2004 16:52:03 +0200 To: Bob Glamm , internals@lists.php.net Message-ID: <20041004145203.GA10654@pharao.serveftp.org> Reply-To: messju mohr References: <20041004143916.GA19506@romulus.a-s-i.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041004143916.GA19506@romulus.a-s-i.com> User-Agent: Mutt/1.4.2.1i X-WebServ-IT-MailScanner-Information: Please contact the ISP for more information X-WebServ-IT-MailScanner: Found to be clean X-WebServ-IT-MailScanner-SpamCheck: not spam, SpamAssassin (score=-0.545, required 5, AWL -1.98, BAYES_00 -4.90, RCVD_IN_DYNABLOCK 2.60, RCVD_IN_NJABL 0.10, RCVD_IN_NJABL_DIALUP 3.54, RCVD_IN_SORBS 0.10) X-MailScanner-From: messju@lammfellpuschen.de Subject: Re: [PHP-DEV] Odd reference => global bug? From: messju@lammfellpuschen.de (messju mohr) On Mon, Oct 04, 2004 at 09:39:16AM -0500, Bob Glamm wrote: > I saw this behavior this morning and was curious if I'd tripped a bug > in PHP (running version 4.3.7 at the moment). I scanned through the > bug list for this particular bug but didn't find it. I'm running it > by you all because I'm not intimately familiar with the reference > system to really be sure that it's a bug and not just my misunderstanding. > > A demonstration script is included below: > globals $x and $v are set to NULL. q() is called > and references globals $x and $v. $x is set to the new class X; > $v is set to a reference to a new class Y (by means of a factory > function in X, a common structure in PEAR). > > My version of PHP prints NULL at the var_dump() statement immediately > following the call to q(); I would expect it to dump an instance of > class Y. So: am I misunderstanding references (and if so, why is the > behavior what it is), is this a duplicate > of another known bug, is this bug fixed in a newer version of PHP, > or should I file a new bug? > > -Bob > > > class Y // class created by factory in X, below > { > function Y($t) { $this->a = $t; } > } > > class X > { > function X() { } > > function &getY($t) // factory method to create Y and return a ref to it > { > $k = new Y($t); > return($k); > } > } > > $x = null; > $v = null; > > function q() > { > global $x, $v; this makes a reference just like $v =& $GLOBALS['v']; would > $x = new X(); // get an X simply to acquire a Y > $v =& $x->getY("here"); // use the factory in X to assign a ref > // to Y to the global $v this overrides the old reference (the one to $GLOBALS['v']) with a new (local) one. this behaviour may look odd, but it is not a bug. do "$GLOBALS['v'] =& $x->getY("here")" instead and $v will be assinged as expected. > } > > q(); // initialize the globals with X and &Y > var_dump($v); // should dump a Y, instead prints NULL ? > > ?> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php