6

I can't believe i'm not able to google anything relevant to this question, but anyway...

My logical assumption would be that scripts which obey all the rules that strict standards dictate would execute faster.

On the other hand, if the scripts WORK without strict standards, then maybe strict standards is just an unnecessary extra verification step in the compiling process...

Is there any official information on what's faster? Thanks.

3Nex
  • 517
  • 6
  • 14
  • 1
    Your assumption is right insofar as strict code (for some definition of “strict”) *can* be executed faster – see e.g. [HipHop](https://en.wikipedia.org/wiki/HipHop_for_PHP). But I think this isn’t done in the official PHP interpreter. Facebook however is working on a VM which does exactly that. – Konrad Rudolph Dec 04 '12 at 14:42
  • 2
    Micro optimization is the root of all evil. However, the strict standards tell you, that you will probably have less problems on the long run. @KonradRudolph I guess he is talking about PHPs own `E_STRICT`-notices – KingCrunch Dec 04 '12 at 14:42
  • 2
    @King Inappropriate quotes are the root of all evil. OP isn’t talking about unnecessary micro-optimisations. – Konrad Rudolph Dec 04 '12 at 14:43
  • 2
    I agree that it is not micro-optimization. Respecting standards has one obvious effect: it doesn't flood your logs with unnecessary warnings and notices. – Tchoupi Dec 04 '12 at 14:44
  • 1
    @KonradRudolph a) It's not a cite from me and b) What tells you, that this are not "unnecessary micro-optimisations"? It seems, that you are talking from something quite different thing. – KingCrunch Dec 04 '12 at 14:45
  • 1
    It's easy enough to find out if you profile your code. – Mike B Dec 04 '12 at 14:46
  • @KingCrunch You are right, OP should clarify if we are talking about strict coding standards, or complying with `E_STRICT` flag. – Tchoupi Dec 04 '12 at 14:46
  • 1
    @KingCrunch What do you mean by “a)”? It’s a well-known quote that’s trodden out whenever somebody wants to optimise something. b) OP asked a general question about code efficiency. There is nothing about micro-optimisation in this question, and the question is certainly not “the root of all evil”. On the contrary: they want to know whether *clean code* may have the the side-effect of being executed more efficiently. – Konrad Rudolph Dec 04 '12 at 14:49
  • 1
    @KonradRudolph Nope, he asked a question about "Is PHP execution any faster with strict standards?". In PHP the term "strict standards" is tightly bound to the `E_STRICT`-error level. And beside that HipHop and derivates are quite nice tools, they are not part of the official PHP-ecosystem and should therefore not be treated as such. Also, I didn't say the _question_ is a root of anything. – KingCrunch Dec 04 '12 at 15:13
  • 1
    @KingCrunch: So you basically admit with your last comment, that your first comment was irrelevant and unneeded? – Evert Dec 04 '12 at 15:18
  • 1
    @King Notice how my comments never claimed that HipHop was part of the PHP ecosystem, quite the contrary. I still think that your initial comment, mentioning “micro optimizations”, is utterly inappropriate here. – Konrad Rudolph Dec 04 '12 at 15:19
  • 1
    I think the question here is `What is strict standards?` or `What does the OP understand by strict standards` – Baba Dec 04 '12 at 15:22
  • @KingCrunch: then what was your point with your 'micro optimizations' comment? Seems completely irrelevant. – Evert Dec 04 '12 at 15:45
  • @Evert Whats your point? What does this have to do with my comment (the one you refered), that Konrads comment went into a wrong direction? – KingCrunch Dec 04 '12 at 15:49

1 Answers1

6

It should be faster..

The simple reason being is that PHP's error triggering system is pretty heavy, and even if E_STRICT errors are suppressed, they still enter the error mechanism (only to be ignored).

But in reality it highly depends on the situation, because I could imagine that working around E_STRICT could in itself also be heavier than the original solution.

Regardless though, using E_STRICT is a smart idea and allows for more portable, future-proof code. However, I would not use performance as a valid reason to start writing strict PHP code.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • +1 Exactly right, every error that would be generated (even if you have `error_reporting(0)`) has a negative impact on performance, because they are still generated even when not reported. This in turn causes extra execution steps to be carried out by the program. – Leigh Dec 04 '12 at 15:22