...

View Full Version : Another question on the registry pattern?



Oatley
10-11-2012, 02:37 PM
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.



$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



$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.

Dormilich
10-12-2012, 07:40 AM
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.


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum