You are here: Re: PHP5 and class inheritance question « PHP Programming Language « IT news, forums, messages
Re: PHP5 and class inheritance question

Posted by Michael Fesser on 12/20/07 00:12

..oO(Logos)

><cowers in the middle as flames go over his head>

Don't worry. In most cases it doesn't matter. But in some rare cases it
might. And then you're looking for an explanation ...

Two years ago this issue came up in a German PHP newsgroup, where a
particular script behaved in a strange and unexpected way. During the
discussion these issues with references and object handles came up. The
conclusion was, that PHP behaved as it should and the object handling
worked as expected. It is (or was) just described in a rather bad and
incomplete way in the manual, hence all the confusion.

>So is this, my current understanding, correct?
>$foo = new Test();
>$a = $foo;
>$b = &$foo;
>
>$foo and $b are both pointing to the same thingie, which in turn
>points to Test().
>$a is pointing to a different thingie from $foo/$b, which in turn
>points to Test().

Yes, the behaviour could be described that way. As said - usually you
don't have to think about these issues.

As an addition: There's an old bug report and also a section in the
manual regarding this issue:

Objects are not being passed by reference
http://bugs.php.net/bug.php?id=32137

http://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new

>Changing either $foo OR $b to point to a new thingie will result in
>BOTH being changed.

Yep, that's the nature of a reference.

>Changing $a to point to a new thingie will leave $foo and $b
>unaffected.

Correct.

Micha

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация