[Solar-talk] Re: Solar::register()
Paul M Jones
pmjones at solarphp.com
Tue May 9 09:35:48 PDT 2006
On May 8, 2006, at 2:39 AM, Antti Holvikari wrote:
> On 5/8/06, Paul M Jones <pmjones at solarphp.com> wrote:
>> // but if you try to register an object with the same name,
>> // it currently throws an exception.
>> $result = Solar::register('example1', 'Solar_Test_Example');
>
> Sorry, I didn't put it right. I meant returning void instead of
> throwing an Exception, only in the case above. I don't neccessarily
> think it's worth throwing an Exception in this case. This way if the
> object with same name is registered and you try to register it again
> the script continues. Do you think this is bad practice?
I hate to call things "bad practice" when I haven't done them myself
at least a few times. ;-)
Having said that, I think it makes sense to let the developer know,
in a way he can't ignore, that he's tried to register something
that's already registered. Then he knows for sure that his attempt
failed, and cannot base future actions on the expectation that it
succeeded.
Otherwise, the developer would need to check the return value of
every Solar::register() call to make sure the register() attempt
worked. I think that's at least as much work, and probably more,
than a try/catch block or an "if (! Solar::inRegistry())" call.
Add to that the fact that inRegistry() is more explicit, so people
reading the code can see exactly what's going on and why.
Does that make sense? Happy to entertain argument here.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list