ZF-6381: Second param to Zend_Registry::get() for default value

Description

Add an optional second parameter to Zend_Registry::get()

In the case of if (!$instance->offsetExists($index)) instead of always throwing an exception, look to see if the second param is not null and return that value. If it's null, then go ahead and throw the exception.

This greatly improves the usability of this method as I won't have to always put it in a try/catch block when there is an acceptable default.

Comments

I see a small problem here: How would you differentiate between "my default value is {{NULL}}" and "please throw an exception if key is not found"? Most likely that would require a third argument to {{Zend_Registry::get()}} - such as {{$throwOnNotFound}} or something like that.

Option 1) (the assumed option requested by this issue) The user just doesn't get to use NULL, that's the price you pay for wanting a throw exception feature.
This is very easily worked around by passing a blank string or a 0 and using that response.

Option 2) Don't have the default be NULL, have it be something unusual like 'throw_exception' Then you can compare to that fixed string and know if an exception should be thrown.

Option 3) Don't define a second parameter and use func_get_arg(1) This president has already been set with the isValid() method in Zend_Validate_Abstract/Zend_Validate_Interface but is difficult to document.

Reassigned to component maintainer