Reply to Storing a reference to an object in another object

Your name:

Reply:


Posted by Rory McKinley on 01/19/05 16:05

Hi All

This is probably just a case of me being Mr Thicky, but maybe someone
can point out the error mf my ways:

I have two classes, call them admin and module. Admin stores login
details as well as a pointer to the DB connection. Module will run
various queries. To do that it needs access to the DB connection
maintained by Admin. Because I don't want to have to keep on passing the
reference to the admin instance, I thought I would store the reference
to the admin instance within the module instance when the object is created:

class Module
{
private $admin_instance;

function __construct($admin_instance)
{
$this->admin_instance = $admin_instance;
}

public function checkConnection()
{
return $this->admin_instance->checkConnection()
}
}

I am using PHP 5 so the reference should be passed and stored in the
relevant object attribute, not so?

Yet, if i call checkConnection it tells me that I am calling a method on
a non-object.print_r() of the module instance makes things even more
confusing: print_r returns:

[admin_instance:private] => [class_name] => blah [admin_instance] =>
Admin Object

which is followed by the various attributes of the admin object
suggesting that the reference to the admin object is indeed within the
module instance.

I hope someone can help with this..

Oh, and before anybody asks I am still busy RTFM, STFW, STFA but with no
joy so far.

--
Rory McKinley
Nebula Solutions
+27 21 555 3227 - office
+27 21 551 0676 - fax
+27 82 857 2391 - mobile
www.nebula.co.za
====================

[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

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