Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93540 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58726 invoked from network); 25 May 2016 21:52:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 May 2016 21:52:11 -0000 Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.128.151 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.128.151 dd1730.kasserver.com Received: from [85.13.128.151] ([85.13.128.151:42393] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/8F-14311-A8E16475 for ; Wed, 25 May 2016 17:52:11 -0400 Received: from dd1730.kasserver.com (dd0800.kasserver.com [85.13.143.204]) by dd1730.kasserver.com (Postfix) with ESMTPSA id 034FC1A801B3; Wed, 25 May 2016 23:52:08 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 95.91.244.236 User-Agent: ALL-INKL Webmail 2.11 To: ajf@ajf.me, internals@lists.php.net Cc: ocramius@gmail.com, bensor987@neuf.fr, me@kelunik.com, smalyshev@gmail.com Message-ID: <20160525215208.034FC1A801B3@dd1730.kasserver.com> Date: Wed, 25 May 2016 23:52:08 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: mails@thomasbley.de ("Thomas Bley") I'm not seeing a problem here: 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 var_dump(isset($a->z)); // true unset($a->z); var_dump(isset($a->z)); // false 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... var_dump(isset($a->x)); // false var_dump(isset($a->y)); // false var_dump(isset($a->u)); // false var_dump(isset($a->v)); // false var_dump(isset($a->w)); // false Regards Thomas >> 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... Fleshgrinder wrote on 25.05.2016 23:38: > 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 > >