Closed rmccue closed 10 years ago
I'm fixing the PHP 5.3+ issue today. I'll leave this open as part of that.
I like what you've done above. Cheers.
I'm fixing the PHP 5.3+ issue today. I'll leave this open as part of that.
For PHP 5.2, singletons with extended classes are actually much harder. You'll need to use debug_backtrace
to find which class was actually called, or override the method in each subclass.
If you're going with 5.2 compatibility, I'd actually get rid of the forced singleton (with getinstance
) and just store the instance in a global variable. It's much nicer to extend.
For PHP 5.2, singletons with extended classes are actually much harder.
I'm frustrated that I didn't catch this before shipping v1.0.0.
If you're going with 5.2 compatibility, I'd actually get rid of the forced singleton (with
getinstance
) and just store the instance in a global variable. It's much nicer to extend.
I think I agree.
Addressed in #8.
getinstance
currently usesself::$instances[ get_called_class() ] = new static
. However, since the plugin assumes PHP 5.3+ (with use of bothget_called_class()
andstatic
), this could be set asstatic::
instead.(Also, contrary to the comment
'self' in this context refers to the current class in use
, it actually refers to the class where the method is defined.)