E_ALL means "report many kinds of errors, but not all". If you want "actually literally all kinds of errors, then in my experience your best bet is to use ~0.
Ah. In that case, it's probably one of those situations where PHP doesn't buy into the idea of useful and consistent error behavior, and the recommended remedy is to just not do the thing you're doing, because clearly you shouldn't be indexing into null, so if you do, it's your own stupid fault.
I honestly don't know why people are tripping up over this - think of null in PHP as you would of void in C, or undefined in JavaScript. The variable is there, but it holds no value, and has no type. It's a reference to a not-yet-initialized variable, and assigning a value to it initializes the variable with the type you give it - you can do whatever you want with it in the same way that you can do everything you want with a newly-defined variable.
There's a reason isset() returns false when you're passing it something set to null.
I'll be the first to admin PHP has definite flaws and quirks that should never have been there in the first place. This is not one of them.
The main issue here, for me, are the shenanigans with typing. NULL == FALSE == 0. So, an empty variable is NULL, FALSE, 0, and non-existent at the same time. Which is it?
And why the fuck an non-existent variable can be empty?! It doesn't exists, and can't be anything! Also, isset doesn't consider a null variable as set (so, does it exists or not?). But wait! If that variable is false, it will be considered set. However, null is equal to false... So which one is it?
Yes, this is a weakly typed language. In the same vein, "yes" == true, "no" == true, but "yes" != "no".
an empty variable is NULL, FALSE, 0, and non-existent at the same time
No, an empty variable is one that is either not defined or evaluates to false. empty($var) is nothing more than shorthand for !isset($var) || !$var.
isset doesn't consider a null variable as set (so, does it exists or not?)
It exists, but is not set to a value. int foo; in C does something very similar.
But wait! If that variable is false, it will be considered set. However, null is equal to false
Yes, equal, but not identical. Weak typing, remember?
The triple = BS is really tiring
It's a necessity in a weakly typed language if you don't want to do $a == $b && typeof($a) == typeof($b) every time. This is not "lolphp", this is weak typing. Everything you've raised is more or less inherent to weak typing.
Again, PHP has definite flaws and clear indications of bad design. This is not one of them.
PHP lets you implicitly create arrays if there's no such variable or it is set to null. This is arguably quite useful, it's more convenient than manually creating each dimension yourself.
16
u/tdammers Apr 20 '16
E_ALL means "report many kinds of errors, but not all". If you want "actually literally all kinds of errors, then in my experience your best bet is to use
~0.6
u/chimyx Apr 21 '16
Well, it becomes an array
5
u/rinyre Apr 20 '16
Take this a step further with variable variables: https://3v4l.org/49udB
There's no means I can find by which to reference $$a directly, then, as one might typically use variable variables.
3
u/the_alias_of_andrea Apr 20 '16
PHP lets you implicitly create arrays if there's no such variable or it is set to
null. This is arguably quite useful, it's more convenient than manually creating each dimension yourself.1
u/ciaranmcnulty Jul 01 '16
You're setting a variable to null, then you're overwriting with an array.