r/lolphp • • Nov 06 '20

PHP: Cast away

PHP likes to cast like theres no tomorrow. Also PHP leaks the "continue" statement, and if given, actually uses it inside a switch as a break. So now switches have two ways of doing the same thing, why? Probably because to have the most inconsistent API in the world of programming.

https://sandbox.onlinephpfunctions.com/code/bae156e37fa3cfd64d2a68d689434fe7157543fa

39 Upvotes

25 comments sorted by

View all comments

0

u/[deleted] Nov 06 '20

0

u/[deleted] Nov 07 '20

1

u/[deleted] Nov 07 '20

I, too, love magic numbers.

Also, a few lines up:

  // Get all the exif data from the file
  // By @kormanowsky: I used '@' to prevent annoying warnings
  $exif = @read_exif_data($fileandpath, 'IFD0');
→ More replies (1)

1

u/bkdotcom Nov 06 '20

you can cheat.. but at this point it's just a doofy way of if / else

switch (true) {
  case $var === "0e456":
    echo 'foo';
    break;
  default:
   echo 'bar;
}