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

howto - phpcs set default code style standard

I know it is easy but nevertheless it is good to have it on one place. This howto shows how you set up a default coding standard in phpcs. First you have to create or download a code style standard. If you want to create one, try this howto. If you already have a standard, try to untar it to:

/usr/share/php/PHP/CodeSniffer/Standards/
You can check if phpcs founds you standard by using:
phpcs -i
Next you just want to define it as your default standard by using:
phpcs --config-set default_standard $artodetoStyleGuide
Thats it, have fun.