[PHP-DEV] Re: [PHP-QA] RE: [PHP-DEV] Re: [PHP-QA] $obj = new foo() patch From: Kirill Maximov (kir <email protected>)
Date: 11/11/00

  Hi again,

Mike Heath wrote:
> > 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 their code
> > (possibly, a LOT of code).
> > But, I think, core team understands importance of compatibility issue.
> That's
> > why 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.

  Well, the only solution I can imagine in this case is to change the way
  how 'global' directive works.
  As far as I've understood, for now, if I declare
  variable as global, I just make it a reference to an element of $GLOBALS
  array (something like this: $a = &$GLOBALS['a']). Or something similar.
  So any code that assigns $a = &{something} will just change the local $a.
  So, the following code prints 5, not 6.

function tt()
{
    global $a;
    $a = 5;
    $b = 6;
    $a = &$b;
}
tt();
echo $a;

  I'm afraid, I suppose it to be a bug, though I've never used references
  explicitly so far (most of my code is for PHP3). I think, 'global'
  shouldn't be implemented as references to $GLOBALS.
  And in this case, Andi's patch will work smoothly.

>
> (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.)

  Its clear ;)

>
> Regards,
>
> Mike

  With best regards,
  KIR

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>