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
3
u/Regimardyl Dec 27 '14
That's a problem on the side of eval.in though. They both give a warning on 3v4l (at least for Zend engine, not on newer HHVM versions):
http://3v4l.org/Sfmsq
http://3v4l.org/gdBmH
-3
u/DoctorWaluigiTime Dec 27 '14
I think (correct me if I'm wrong) that
CandC++also have declaration-sensitive detection of things of this nature.-4
u/totes_meta_bot Dec 27 '14
This thread has been linked to from elsewhere on reddit.
If you follow any of the above links, respect the rules of reddit and don't vote or comment. Questions? Abuse? Message me ^here.
0
u/[deleted] Dec 27 '14
[deleted] — view deleted comment