Re: Re: RE: [PHP-DEV] Re: [PHP-QA] $obj = new foo() patch
| From: | Zeev Suraski | Date: | Sat, 11 Nov 2000 23:41:03 +0000 |
| Subject: | Re: Re: RE: [PHP-DEV] Re: [PHP-QA] $obj = new foo() patch | ||
| References: | 1 | Groups: | php.dev php.qa |
| Request: | Send a blank email to php-qa+get-1646@lists.php.net to get a copy of this message | ||
Actually, altering $GLOBALS is fine, and is sometimes the only way of doing some reference-related things...
Zeev
At 22:48 11/11/2000, Richard Lynch wrote:
As I understand it, altering $GLOBALS directly is *UNSUPPORTED* -- Don't do it. Use global and an assignment. Don't dink around with an internal structure ($GLOBALS) to do something where there is instead a documented solution. I believe Rasmus or Zeev even said this on the PHP General list, way back when. ----- Original Message ----- From: Mike Heath <heathm@effinitylabs.com> To: Kirill Maximov <kir@actimind.com> Cc: Andi Gutmans <andi@zend.com>; PHP Development <php-dev@lists.php.net>; <php-qa@lists.php.net>; <danjrod@terra.es> Sent: Friday, November 10, 2000 7:09 PM Subject: RE: [PHP-QA] RE: [PHP-DEV] Re: [PHP-QA] $obj = new foo() patch Kirill and others,-- Zeev Suraski <zeev@zend.com> CTO, Zend Technologies Ltd. http://www.zend.com/Hmm. I thought that $GLOBALS['a'] = new A; is absolute equivalent to global $a; $a = new A; I don't care in this example what is returned by operator 'new'. I suppose, that $a in second case should be absolutely equivalent to GLOBALS['a'] regardsless right part of '=' sign.I though that too but apparantly what happens is $a is created inside the context of the function and points to the data of the real global $a so if you do something like $a = &$foo inside the function the real $a's reference won't change. This should probably be documented better since saying something "PHP doesn't support C like pointers" doesn't quite cut it. It took me quite some time (and a number of bug postings) to figure this out.Anyway, I don't understand why Andi's patch can work in both cases. OK, 'new' returns reference. But $a should be === $GLOBALS['a'], IMO. Or I've missed something?Explained above why not. I fully agree that as that is what is expected but after looking under the hood of PHP a bit I can see why it isn't. Of course if I had it my way I'd just get rid of the whole global $foo thing all together. :)If we want to force 'rich' OO design, let's wait until PHP 5.0. IMO, a few peoply will upgrade to 4.0.4 if they'll have to rewrite theircode(possibly, a LOT of code). But, I think, core team understands importance of compatibility issue.That'swhy Andi reversed the patch for now, isn't it? ;-)Well I have to agree with you there. There are a lot of OO features I would love to see in PHP but I'm certainly not counting on them until future versions. The problem (regarding Andi's patch) is that the expected behavior of: <?php class foo {function foo($a) { global $ListOfObjects;$this->a = a; $ListOfObjects[] = &$this; }$bar = new foo() ?> would be that $ListOfObjects[0] and $bar referenced the same data. They do not. This is very frustrating to many people are there are 5 or more bugs in the bugs database pointing this out. I'm convinced this is a serious issue and needs to be fixed. I can only pray that *some* fix will get into PHP 4.0.4. (BTW -- regarding my explanation above concerning the difference between global $foo and $GLOBALS['foo']. This example will still work since I'm not changing the reference to $ListOfObjects just its array members.) Regards, Mike -- PHP Quality Assurance Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-qa-unsubscribe@lists.php.net For additional commands, e-mail: php-qa-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net