Reply to Re: I need $this->self to be identical to and reference to $this, but how in PHP 5.2+?

Your name:

Reply:


Posted by comp.lang.php on 01/08/07 11:50

hackajar wrote:
> http://us3.php.net/manual/en/language.oop5.basic.php
> Check out example 19-4 & 19-5

Ok, but I don't get it. I understand assignment properties and
instantiation but I guess not enough to see how that pertains to what
I'm doing here.

>
> Hackajar
> comp.lang.php wrote:
> > [PHP]
> > <?
> > class EditResultGenerator extends MethodGeneratorForActionPerformer {
> >
> > /**
> > * Create an instance of itself if $this does not yet exist as an
> > EditResultGenerator class object
> > *
> > * @access private
> > * @see is_class
> > */
> > function &generateSelf() { // STATIC VOID METHOD
> > if (!is_object($this) || @!is_class($this, 'EditResultGenerator')) {
> > $this->self =& new EditResultGenerator();
> > } else {
> > $this->self =& $this;
> > }
> > }
> >
> > }
> > ?>
> > [/PHP]
> >
> > This self-generating function serves a purpose to ensure that if part
> > of the application does this:
> >
> > [PHP]
> > <?
> > EditResultGenerator::getResult();
> > ?>
> > [/PHP]
> >
> > That it will work *exactly* the same as if I did this:
> >
> > [PHP]
> > <?
> > $edit =& new EditResultGenerator();
> > $result = $edit->getResult();
> > ?>
> > [/PHP]
> >
> > However, I cannot change hundreds of lines of code from the former to
> > the latter just to ensure instantiation is uniform, so I'm stuck with
> > the fact that I have to generate a $this->self EditResultGenerator
> > class object if $this does not exist, otherwise, $this->self must be
> > *absolutely identical* to $this, in fact, be a reference!
> >
> > This works beautifully in PHP 4.3+, but bombs in PHP 5.2.
> >
> > How can I get it to work in PHP 5.2+?
> >
> > Phil

[Back to original 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

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