Re: class and subclass reference question

From: Date: Wed, 05 Jan 2005 02:34:13 +0000
Subject: Re: class and subclass reference question
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35349@lists.php.net to get a copy of this message
On Tue, 4 Jan 2005 10:59:48 -0800, Nedjo Rogers <nedjo@gworks.ca> wrote: > I'm drafting a PEAR package proposal in PHP 4 (for providing a > standards-compliant "web map service" interface to the Image_GIS package) > and could use some help with subclass references. > > When creating a subclass object, I wish to create a reference to the > principal object so that the subclass object can, e.g., update properties in > the principal object. > > The tutorial at > > > http://www.phppatterns.com/index.php/article/articleview/23/1/2/ > > explains how this can be done from external calls (i.e., not internal to the > classes) using the & reference operator. However, when I try to pass > references within classes, I get copies instead (e.g., changes made by > subclass objects are not registered with the principal object). > > An example: > [snip] > Is there a standard approach to this problem? > There was discussion of a similar problem on the list just a short while ago (search for DataGrid and factory). There are apparently some problems with constructors and references. If you do $obj =& new Obj(); it may or may not help. You may be better off setting this in a function call instead of the constructor. -- Justin Patrin

« previous php.pear.dev (#35349) next »