Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 02:37 PM   PM User | #1
Oatley
New Coder

 
Join Date: Sep 2012
Posts: 76
Thanks: 61
Thanked 0 Times in 0 Posts
Oatley is an unknown quantity at this point
Another question on the registry pattern?

Hello, before I was looking at the registry pattern and from what I read I can pass in values to store in an array as storage.

PHP Code:
$obj = new Registry();
$obj->set('anything''anyvalue'); 
However, I've just seen some examples whereby rather than using a set method to just pass in a key and a value as a string, it can pass in the 'new' keyword with a pre-defined class like

PHP Code:
$obj = new Registry();
$obj->set('anything', new ArrayIterator);
//or
$obj->set('anything', new stdClass); 
So using the registry class can you pass in only predefined classes? Or could I pass my own class I create in the registry pattern?

If you can pass in one of your own classes, how would you use it within the registry pattern? Does anyone have a basic example, or is it mainly used when passing in strings as per my first code example?

Thank you very much.
Oatley is offline   Reply With Quote
Old 10-12-2012, 07:40 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,907
Thanks: 10
Thanked 293 Times in 289 Posts
Dormilich is on a distinguished road
Quote:
So using the registry class can you pass in only predefined classes? Or could I pass my own class I create in the registry pattern?
you can pass in whatever you want, the Registry doesn’t care about the data type. your own classes only need to be loaded before you instantiate them.

Quote:
If you can pass in one of your own classes, how would you use it within the registry pattern?
afaik, not at all. i.e. a Registry is just a storage container.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:51 AM.


Advertisement
Log in to turn off these ads.