Re: [RFC][Vote] Typed Properties
| From: | Fleshgrinder | Date: | Wed, 25 May 2016 21:38:13 +0000 |
| Subject: | Re: [RFC][Vote] Typed Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93537@lists.php.net to get a copy of this message | ||
On 5/25/2016 11:35 PM, Thomas Bley wrote:
> Following "Type safety is the goal of this RFC, not validating objects.", it would be
> better to do implicit casting for uninitialized properties (whenever implicit casting is possible)
> or use null for nullable types:
>
> class A {
> public int $x;
> public ?int $y = null;
> public int $z = 42;
> public ?int $u;
> public ?datetime $v;
> public datetime $w;
> }
>
> $a = new A;
> var_dump($a->x); // 0 + notice
> var_dump($a->y); // null
> var_dump($a->z); // 42
> unset($a->z);
> var_dump($a->z); // 0 + notice
> var_dump($a->u); // null + notice
> var_dump($a->v); // null + notice
> var_dump($a->w); // Fatal error, uninitialized...
>
This was proposed many times but it renders checks whether something was
initialized or not completely useless and is not really a solution to
the problem at hand.
--
Richard "Fleshgrinder" Fussenegger
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc