Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    76
    Thanks
    61
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,474
    Thanks
    13
    Thanked 361 Times in 357 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •