Re: Array dereferencing of scalars
| From: | Rowan Collins | Date: | Thu, 11 Jun 2015 08:59:14 +0000 |
| Subject: | Re: Array dereferencing of scalars | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86591@lists.php.net to get a copy of this message | ||
Yasuo Ohgaki wrote on 11/06/2015 00:50:
If PHP should return NULL always against NULL variables, we may be better to reconsider these behavior. [yohgaki@dev Download]$ php <?php $v = NULL; $$v; PHP Notice: Undefined variable: in - on line 3This is not complaining that $v is NULL, it is warning you the same as if you wrote $v = 'some_name_you_never_assigned_to'; $$v; Somewhat surprisingly, you can actually assign to the variable whose name is NULL: http://3v4l.org/5pXJg
[yohgaki@dev Download]$ php <?php $v = NULL; $v(); PHP Fatal error: Uncaught EngineException: Function name must be a string in -:3 Stack trace: #0 {main} thrown in - on line 3This one has given a different message because of it being a non-string value, but would be equally fatal if you tried to call any undefined function. Would coercing NULL to an imaginary function which returns NULL actually be useful for anything?
I don't care much whether these yield NULL always or raise error/exception, but there should be consistency.I see no reason why these cases need to be consistent, just because they both involve NULLs. It's all about the action you invoke, not just the value something's interpreted as. -- Rowan Collins [IMSoP]