Last Updated: January 28, 2019·
A safe constructor in an extending class
Sometimes when you extend a class that's not yours, in a web framework for example, you need to have a constructor for your own class. You don't want to just put a constructor in there, because if the parent class has a constructor, it will be overridden. You could call
parent::__construct() with the right arguments, but in a newer version of the the parent class, the signature of the constructor may change, and you would have broken it.
**kwargs for this, but in PHP the closest I have found is this:
call_user_func_array(array('parent', '__construct'), func_get_args());
Written by Willem van der Jagt
Have a fresh tip? Share with Coderwall community!
Post a tip
Best #Php Authors
Sponsored by #native_company# — Learn More