Skip to content

Constructor in Interfaces? Again no

Its a rainy day outside so i clicked (if it is clicking when you use CTRL+F ;-)) through the word wide web and found an entry by Ralph Schindler about PHP Constructor - Best Practise. Ralph explained why

Strict standards: Declaration of Bar::somemethod() should be compatible with that of Foo::somemethod()
wont raise an error when you define another constructor signature in an extended class like
class \Foo { public function __construct(array $bar) { //put code in here } } class \Bar extends \Foo { public function __construct(array $options, \foo $foo { //put code in herer } }
If you want to know why, click on the link and read the article :-). What i liked most in his article was his consolidation of my one coding style by writing:
Moreover, constructors should not appear in interfaces.
as i asserted in an older entry. But you really should read the whole article while he is talking about the prototype pattern. Also the comments can help you to forget the rain outside ;-).