1 # Pragmatic Heterogeneous Proofread đ» đ«
5 First thing first, this is not supposed to be just slander about PHP ~like I am used to do~ but a comprehensive list of errors that are atributed to PHP and proof (or lack thereof) of those errors across multiple versions of PHP.
6 Also those errors will be compared to a correct design on other langs showing how those problems could be improved or so.
10 So, this is called a proofread mainly because it is a revision of an old post I usually link that was made on eevee blog talking about how bas the design of PHP is. you can see the post [here.](https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ "Not for the faint of heart")
12 And as they say on the blog we will check on how PHP is ~not~ a **predictable, consistent, concise, reliable, debuggable** lang.
14 ## List of stuff we will be visiting
16 + Searching arrays return false and false is converted to 0 so it will work as if you had found the item on the first index
17 + `"foo" == TRUE` and `"foo" == 0` but `"TRUE" !=0`
18 + `123=="123foo"` but `"123" != "123foo"`...huh
19 + `6 == " 6"` and `"4.2" == "4.20"` and `"133" == "0133"` but `133 != 0133` because 0133 is octal. `"0x10" == 16` and `"1e3" == "1000"`
20 + === compares object ande type expect for objects where === means that both are the same object and == compare value and type, which is what === does for other types.
21 + `NULL < -1` and `NULL == 0`, so this can cause nondeterministic sorting
22 + `"123" < "0124"` no matter what, even with casting
23 + you can write `var[]` or `var{}` for indexing
24 + if you use `[]` on a non-array it silently returns null
25 + left associative `?:` that was later changed for non-associative by enforcing parenthesis on php8
26 + no variable declaration, so if you need a global variable this could result into a local variable silently beign created, damaging the scoping of the lang.
27 + function and class names are case insensitive while variables are.
28 + `array()` or `list()` look like functions but are not functions, there are more stuff afected by this
29 + the `(int)` casting looks like a casting from C but `int` does not actually exists, so this is a standalone token just to look like C, same goes for integer bool, boolean, float, double and real casting tokens.
30 + `(array)` and `(object)` casting...huh, can someone explain?
31 + `include()` just dumps the source from another file into your file, there is no real module system on PHP.
32 + including a file adds alll of its variables into the current function scope and gives that file access to your variables too, but classes and functions are dumped into global scope. this is because there are not local functions or classes
33 + appending to an array with `$foo[] = $bar`, i mean....lolz
34 + `echo` is not a function, it is a _statement?_
35 + `endif` but also brackets?
37 + HORRIBLE DEBBUGING EXPERIENCE [as expressed in this phpsadness post](http://phpsadness.com/sad/44)
38 + ... I am done with the nonexisting error handling, there is more on the blog but it will all be tested
39 + well, one more thing is that errors and exceptions are not the same so `try/catch` wont with errors and error handlers are not triggered by errors.
40 + [functions are expensive](https://web.archive.org/web/20170704181231/http://www.phpwtf.org/php-function-calls-have-quite-some-overhead "yes, this is ancient, I know")
41 + when calling a function the extra arguments are just ignored and missing arguments are just _NULL_ except with builtin functions where extra arguments raise an error.
42 + OOP IS NONSENSICAL (yes, I know I promised no slander but we all saw it coming)
48 > I canât even say whatâs wrong with PHP, becauseâ okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there.
50 > You pull out a screwdriver, and you see itâs one of those weird tri-headed things. Okay, well, thatâs not very useful to you, but you guess it comes in handy sometimes.
52 > You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.
54 > You pull out the pliers, but they donât have those serrated surfaces; itâs flat and smooth. Thatâs less useful, but it still turns bolts well enough, so whatever.
56 > And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And thereâs no clear problem with the set as a whole; it still has all the tools.
58 > Now imagine you meet millions of carpenters using this toolbox who tell you âwell hey whatâs the problem with these tools? Theyâre all Iâve ever used and they work fine!â And the carpenters show you the houses theyâve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.
60 > Thatâs whatâs wrong with PHP.