Re: Re: OOP Problems
| From: | James Tan | Date: | Sun, 15 Jul 2001 03:26:35 +0000 |
| Subject: | Re: Re: OOP Problems | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-57917@lists.php.net to get a copy of this message | ||
oh,
i didn't realise how php is as flexible as vb :)
yeah.. ops, missed out the owner->test1 does not exist :)
thanx for tips :)
teo@gecadsoftware.com wrote:
> Hi u007!
> On Sun, 15 Jul 2001, u007 wrote:
>
> > hie..
> > it's simply u did not declare ur class variable...
> >
> well, actually you don't have to declare them, you can add members as you go
> (as opposed to C++ for example)
>
> > class ctest
> > {
> > var $owner;
> >
> > function ctest(&$owner)
> > {
> > $this->owner = $owner;
> > }
> >
> > function foo()
> > {
> > echo "test!<br>";
> > }
> > }
> >
> > hope it works :)
> > regards,
> >
> > James
> >
> > Andrew Kirilenko wrote:
> >
> > > Hello!
> > >
> > > I have following problem:
> > >
> > > <?
> > > $container = new ccontainer();
> > > $container->init();
> > > $container->test1->foo();
> > > $container->test2->foo();
> > > $container->test2->owner->test1->foo();
> > > $container->test1->owner->test2->foo();
> > >
> > > class ccontainer
> > > {
> > > function ccontainer()
> > > {
> > > }
> > >
> > > function init()
> > > {
> > > $this->test1 = new ctest(&$this);
> > > $this->test2 = new ctest(&$this);
> > > }
> > > }
> > >
> > > class ctest
> > > {
> > > function ctest(&$owner)
> > > {
> > > $this->owner = $owner;
> > > }
> > >
> > > function foo()
> > > {
> > > echo "test!<br>";
> > > }
> > > }
> > > ?>
> > >
> > > Output of this script is:
> > > --->
> > > test!
> > > test!
> > > test!
> > > Fatal error: Call to a member function on a non-object in c:\www\a.php on
> > > line 8
> > > <---
> > >
> > > How to solve this problem???
> > >
> > > Best regards,
> > > Andrew Kirilenko,
> > > Senior Programmer / System Administrator,
> > > Internet Service.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> -- teodor