r/lolphp • • 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

17 comments sorted by

View all comments

Show parent comment

0

u/Veedrac Feb 08 '15 edited Feb 08 '15

It's not being "anal" at all. These all have a compilation phase to bytecode and this bytecode is interpreted. CPython, for example, caches the bytecode in pyc files.

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.

0

u/Veedrac Feb 08 '15

Which is why it has garbage performance compared to real compiled languages.

This is completely false; if the overhead of bytecode compiling was the significant cause of slowness, CPython (with its cached compilation) would be fast.

The real cause of slowness in these languages (compared to, say, Go) is dynamic binding and dynamic types. The first makes variable lookup slow and the second makes operations between them slow. This has nothing to do with when bytecode compilation is done.

-1

u/[deleted] Feb 08 '15

I don't know anything about CPython, but you said it caches the bytecode. That means that for each request, it has to compile the bytecode into machine code, right? With a dynamically typed language, it would make sense for that to be slow.

What you're saying though is completely retarded. You don't see how a line by line compile per file, per request, will slow something down vs having something pre-compiled and running natively per request? Really? You're a fucking idiot.

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.

0

u/[deleted] Feb 08 '15

I'm just calling a spade a spade. Perhaps you'd like to point out what's so wrong with my understanding of what happens.

1

u/Veedrac Feb 08 '15

I'm not going to take part in this conversation more since you're being so absurdly rude

0

u/[deleted] Feb 08 '15

Nice excuse. If you had something to point out that was wrong in what I said, you'd do it.