8

TIL: PHP if statements don't have block scope.

I didn't know this, was surprised and thought "well, huh".

Comments
  • 2
    It's actually pretty useful. I use it quite often myself (:
  • 2
    @h3rrcrypt099 I like it but I'm still unsure if it should be used as it could make something harder to understand.
  • 1
    It's a decent substitute for if expressions like those of Rust, although the flow of values is less clear.
  • 1
    While it can be useful, I fucking hate how PHP handles variable scope.
  • 1
    @Polymorphism Yup. That's why one should use it with care (about the person who is gonna read that code in the future)
  • 0
    just wait until you find out about `calc` :)
  • 2
    @SuspiciousBug I've just looked up `calc` on the PHP docs and I can't find a function named that :/
  • 0
    @Polymorphism in PHP you can execute commands with ticks. On Windows,

    `calc`;

    will open the calculator app! 😊😞😔
  • 1
    @SuspiciousBug Well I didn't know that either lol. That's crazy.

    I'm not on Windows so I ran `php --interactive` to test `echo `ls`;` in the REPL and sure enough I get the contents of the current dir 😅.
Add Comment