Re: singleton problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ryan Sexton once wrote:

> After quickly looking (I haven't tested this), but I believe you are
>  passing only a copy of your singleton. I believe you need to add an
> "&" in front of your function name to return a reference to the
> return value.

That's correct. Here's a diff:

- $GLOBALS['__useful_stuff'][$class] = new $class();
+ $GLOBALS['__useful_stuff'][$class] =& new $class();

>> Peter Bowyer wrote:
>>
>>$d =& UsefulStuff::singleton('Display');
>>$c =& new Client;
>>print $d->getText() . "\n"; // Should print Default
>>$c->changeName('Peter');
>>print $d->getText() . "\n"; // Should print Peter	

For me, it did print Default and Peter (as expected). But then I 
realized I was running PHP 5.0.1, and objects (and large arrays) are 
automatically referenced (PHP5). Gets those ugly ampersands out of the code!


-- 
[ Rajesh Kumar ]





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux