Re: Class not functioning
| From: | Shawn McKenzie | Date: | Wed, 16 Dec 2009 00:48:09 +0000 |
| Subject: | Re: Class not functioning | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300541@lists.php.net to get a copy of this message | ||
Sorry, and then I didn't keep it on list :-(
Shawn McKenzie wrote:
> Please reply to the list. Just google for "php registry pattern". Here is a very
> basic example. There are better OOP people here than I.
>
> class Registry {
> protected $_objects = array();
>
> function set($name, &$object) {
> $this->_objects[$name] =& $object;
> }
>
> function &get($name) {
> return $this->_objects[$name];
> }
>
> }
>
> // in main code somewhere
> $Registry = new Registry;
> $Meetgreet = new Meetgreet;
> $Notify = new Notifier;
> $Registry->set('Meetgreet';, $Meetgreet);
> $Registry->set('Notify', $Notify);
>
> // in Meetgreet
> $Registry = new Registry;
> $Notify = $Registry->get('Notify');
>
> I'll post a singleton when I have more time.
>
> Allen McCabe wrote:
>> Thank you for your response! Your answer is intriguing, and I would
>> love some extrapolation!
>>
>> Meetgreet is only needed on 1, maybe 2 pages, so including it globally
>> is not needed, and because all meetgreet business is done on a single
>> page, so it is currently uncessary (however I will admit it isn't
>> extendible this way).
>>
>> So what is this registry pattern you speak of?
>>
>> Thanks!
>> Allen
>>
>> On Tue, Dec 15, 2009 at 2:30 PM, Shawn McKenzie <nospam@mckenzies.net
>> <mailto:nospam@mckenzies.net>> wrote:
>>
>> Allen McCabe wrote:
>> > Hey all (and Nirmalya, thanks for the help!),
>> >
>> >
>> > I have a question that I just can't seem to find via Google.
>> >
>> > I want to be able to add messages to a qeue whenever my classes
>> complete (or
>> > fail to complete) specific functions. I think have a call within
>> my html to
>> > my Notifier class to print all qeued messages (via a function
>> 'printQ').
>> >
>> > How do I access a globally instantiated class from within
>> another class?
>> >
>> > Example:
>> >
>> > <?php
>> >
>> > // INSTANTIATE
>> > $Meetgreet = new Meetgreet;
>> > $Notify = new Notifier;
>> >
>> > ...
>> > ...
>> >
>> > $Meetgreet->deleteSingle($id, 1); // This completes a function
>> within
>> > Meetgreet class. That function needs to be able to use the
>> Notifier function
>> > addtoQ(), how would this be accomplished?
>> >
>> > ?>
>> > ...
>> > ...
>> >
>>
>> Several ways to do it. One would be to make the Meetgreet a singleton
>> if it really is, and then use its static getInstance. I would
>> probably
>> use a registry pattern though.
>>
>> --
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>> <http://www.spidean.com/>
>>
>>
>