You are here: Re: Parent Objects « PHP Programming Language « IT news, forums, messages
Re: Parent Objects

Posted by Rik on 01/13/07 10:24

paul.j wrote:
> I have
>
> class thechild{
> function sayTest()
> {
> parent::test(); // this right???
> }
> }
>
> class theparent{
> function test()
> {
> echo "test";
> }
> function __construct()
> {
> $e = new thechild();
> $e->sayTest();
> }
> }
>
> How do i get this to work ? I am trying to get a one class (A) to
> create another class (B) within it, but the class B must be able to
> call a function from class A. Any ideas?

You could make named class variables. It's up to yourself they work though:

class thechild{
var $parent;
function __construct(&$object){
$this->parent =& $object;
}
function sayTest()
{
$this->parent->test();
}
}
class theparent{
var $child;
function test()
{
echo "test";
}
function __construct()
{
$this->child = new thechild($this);
$this->child->sayTest();
}
}
--
Rik Wasmus

 

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

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