Re: Re: Strange notation to create object

From: Date: Fri, 24 Jun 2005 18:09:13 +0000
Subject: Re: Re: Strange notation to create object
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.general 
Request: Send a blank email to php-general+get-217560@lists.php.net to get a copy of this message
Robert Cummings wrote: ...
Yeah, *grin*. And on that note, there are times when you will actually want $foo = &new SomeClass(); versus $foo = new SomeClass(); since assigning by reference will break any previous references -- something I forgot to mention to Matthew Weier when he challenged the relevance of the snippet I sent. Cheers, Rob.
Indeed... Matt, hope you see this one. I was quite surprised by the results as well! Rob, since you're explaining this to us now then I assume that the dev team is well aware of this issue and this is intended behavior... or is this something that will be fixed/changed so that we don't have copies of references floating around? Because that seems very unintuitive to me... references to references seems like a better "default" behavior unless there's a good reason why we shouldn't change. #!/usr/local/bin/php <?php
    class a
    {
	    public $changes = 1;
	    function __construct() {
		    $this->changes++;
	    }
    }
    class b
    {
    }
    $aObj = new a();
    $aRef = &new a();
    $bObj = new b();
    $foo1 = $aObj;
    $foo2 = $aObj;
    $foo3 = $foo1;
    $foo4 = &$foo2;
    $foo5 = $aRef;
    $foo6 = &$aRef;
    $foo1->changes = 'I changed!';
    echo "------------------\n";
    print_r( $foo1 );
    print_r( $foo2 );
    print_r( $foo3 );
    print_r( $foo4 );
    print_r( $foo5 );
    print_r( $foo6 );
    $foo1 = $bObj;
    $foo2 = $bObj;
    $foo5 = $bObj;
    echo "------------------\n";
    print_r( $foo1 );
    print_r( $foo2 );
    print_r( $foo3 );
    print_r( $foo4 );
    print_r( $foo5 );
    print_r( $foo6 );
    $foo1 = &$aObj;
?> -- NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-general&w=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php

« previous php.general (#217560) next »