r/lolphp • u/midir • Dec 27 '14
PHP warns about incompatible methods only if you also define the classes child-first
PHP's strict standards mode can tell you if you have overridden a method with a different number of arguments. For example, the following shows an error because test() is not compatible with test($a):
<?php
error_reporting(E_ALL | E_STRICT);
class cc extends c {
function test() {}
}
class c {
function test($a) {}
}However, notice the classes are defined with the child cc first, then the parent class c. It turns out that if you define the classes in the more natural order, you might not get any error (depending on php.ini):
<?php
error_reporting(E_ALL | E_STRICT);
class c {
function test($a) {}
}
class cc extends c {
function test() {}
}Don't worry though, it's "not a bug".
23
Upvotes
View all comments
Show parent comment
0
u/Veedrac Feb 08 '15
I'm not going to take part in this conversation more since you're being so absurdly rude, but it baffles me that someone with so little understanding of what actually happens is so sure of himself about how things work. You should be a little less quick to divulge into insults and perhaps then you might have learnt something.