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 ;-).

Translate to de es fr it pt ja


No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Markdown format allowed
Form options