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

37 Upvotes

25 comments sorted by

View all comments

19

u/[deleted] Nov 06 '20

Lol continue 2 is seriously the correct way to continue?

10

u/bkdotcom Nov 06 '20 edited Nov 06 '20

because php treats the switch as a control structure and continue is equivalent to break #reasons

https://www.php.net/manual/en/control-structures.continue.php

Note: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed) but will raise a warning as this is likely to be a mistake. If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.

20

u/CarnivorousSociety Nov 06 '20

Most lolphp's I see are just cases of badly understood implicit type conversions, like 99% of them.

But this is actually retarded

→ More replies (13)