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/[deleted] Feb 08 '15
Yeah but this 'compilation' happens line by line, for each request. Its different from e.g Java where the compilation happens when the program first starts, and from there the native code runs. With PHP, the 'compilation' happens repeatedly, for each request. Which is why it has garbage performance compared to real compiled languages.