Re: Container or Calling Class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/5/24 phphelp -- kbk <phphelp@xxxxxxxxxxx>:
> Hey -- folks -- -- -
>
> I am trying to figure out one aspect of PHP's object model.
>
> Is it good practice to have a class be a property of another class? In other
> words:
>
> class foo_handler {
>        function add_bar() {
>                include bar_class.inc;
>                $this->bar_handler = new bar_handler;
>        }
>
> }
>
> So one would have language in a foo_handler function like:
>
> $this->bar_handler->bar_toast("Rye",$settings);

This is pretty common practice. However, it's worth pointing out that
putting the include statement there will prevent a number of potential
performance improvements on the part of the PHP compiler and any
bytecode caches that might be active.

> If so, can the bar_handler->bar_toast() function call a function in the
> container class (foo_handler)? "Parent" is used in some OOP languages for
> this type of hierarchy, but not PHP. I have fooled around with the scope
> resolution operator, but either that doesn't do it or I can't nail the
> syntax.
>
> Anyone care to illuminate this for me?

I've never heard of this being possible in any language, never mind
PHP. The parent keyword you mention refers to the parent class not the
container, and works just as well in PHP as in other languages. Any
OOP implementation that allows a class to call functions in a
container class would be breaking one of the cardinal rules of OOP.

-Stuart

-- 
http://stut.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux