Re: [RFC][Vote] Typed Properties
| From: | Fleshgrinder | Date: | Thu, 26 May 2016 10:16:07 +0000 |
| Subject: | Re: [RFC][Vote] Typed Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93556@lists.php.net to get a copy of this message | ||
On 5/26/2016 12:03 PM, Rowan Collins wrote:
> Could you summarise what your proposal actually is; I got a bit lost
> with what your long list of examples was trying to show me.
>
To summarize it: we should change the behavior of isset() to work
exactly the same way as it does for associative array keys if they have
null assigned to them.
Shorter example of current PHP implementation:
$a = ['x' => null];
var_dump(isset($a['x'])); // false
var_dump(array_key_exists($a, 'x')); // true
$o = (object) ['x' => null];
var_dump(isset($a->x)); // true
var_dump(property_exists($a, 'x')); // true
PHP 8
$o = (object) ['x' => null];
var_dump(isset($a->x)); // false
var_dump(property_exists($a, 'x')); // true
This would actually be more consistent with the isset() behavior
together with associative arrays and it would allow us to handle typed
properties that where not initialized (as illustrated in the longer
example).
On 5/26/2016 12:03 PM, Rowan Collins wrote:
> Can you provide a reference for that? The only thing mentioned in the
> changelog in the manual is this rather rare situation:
>
> $foo = 'a string';
> isset($foo['some_key']);
>
> $foo['some_key'] doesn't actually have much of a meaning in that case,
> anyway, and it has nothing to do with initialisation.
>
Just tested it with those ancient versions and you are right that I
interpreted that sentence incorrectly. The behavior of isset() with
array keys that were explicitly set to null never changed.
ref: https://3v4l.org/TS621
However, this does not change my proposal. :)
--
Richard "Fleshgrinder" Fussenegger
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc