Re: Array dereferencing of scalars
| From: | Rowan Collins | Date: | Tue, 09 Jun 2015 12:43:36 +0000 |
| Subject: | Re: Array dereferencing of scalars | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86520@lists.php.net to get a copy of this message | ||
Christoph Becker wrote on 09/06/2015 13:35:
Current behavior: <?php $v = NULL; echo $v->foo->bar; ?> Notice: Trying to get property of non-object in %s on line %d Notice: Trying to get property of non-object in %s on line %d So trying to access a property on NULL gives a notice, but trying to access an element of NULL shouldn't? Also note, that chained property access raises multiple notices.Again, assignment works differently here: $v = NULL; $v->foo->bar = 42; // Warning: Creating default object from empty value Interestingly, only one Warning is issued for this case, even though the inner value must also be created. This seems like a more useful behaviour, because it doesn't clutter the log/output with repeated notices about a single line. Regards, -- Rowan Collins [IMSoP]