4

Today I learned that PHP disables assertions by default on prod via:

zend.assertions = -1

Which means, it is running in "production mode". PHP then simply ignores all those pesky assertions, so your code can run superfast! 🤡

Guess how I found out... I'm sick to my stomach right now.

Comments
  • 5
    Aren't assertions in nearly every language just for debugging?
  • 3
    Idk just rtfm:
    "Assertions should be used as a debugging feature only."
    https://php.net/manual/en/...
  • 2
    @j0n4s

    This is how C++ works. Assertions are on when compiled in debug mode. Off when compiled in release mode.
  • 1
    @Demolishun python also has this, but it removes them only when you run it with 'python -O' (which sole purpose is to remove assert and set the builtin __debug__ boolean to false) but idk if anyone does this. I just checked and rust's assert_eq does also run in release mode but there is a debug_assert.
  • 3
    I‘m all for hating PHP but to be fair, yup: asserts are disabled for release/prod in every language that I worked with so far.
  • 4
    Asserts are not for error handling.

    They're debugging helpers.

    Thus most languages treat them as conditionals, short wrapper ala "if debug ... do X".

    Thus in most languages it will be stripped by the compiler / ignored by the runtime engine, which is completely correct.

    If you utilize a debugging aid as an error handler or even worse as an go-to statement, please please please relearn the basics of the language.

    It is wrong for so many reasons and definitely a cardinal sin.
  • 2
    On the flip side, debug-only assertions are allowed to be really expensive. When I'm fixing bugs I add assertions for almost any invariant I can think of and many of them can remain in the code afterwards.
  • 0
    @zvyn yes, I wish they'd deprecate this behaviour
  • 0
    absolutely insane behavior
Add Comment