Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93586 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99044 invoked from network); 26 May 2016 20:08:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2016 20:08:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; 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:41895] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/4F-17600-AB757475 for ; Thu, 26 May 2016 16:08:27 -0400 Received: from dd1730.kasserver.com (dd0801.kasserver.com [85.13.143.205]) by dd1730.kasserver.com (Postfix) with ESMTPSA id 9DB561A803F5; Thu, 26 May 2016 22:08:23 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 217.240.51.196 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <20160526144023.2A2A11A800A7@dd1730.kasserver.com> To: ajf@ajf.me, internals@lists.php.net, fsb@thefsb.org Message-ID: <20160526200823.9DB561A803F5@dd1730.kasserver.com> Date: Thu, 26 May 2016 22:08:23 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: mails@thomasbley.de ("Thomas Bley") it's not so magic, rather think of (int)null, (float)null, (string)null, (array)null, etc. Typed properties could be defined as nullable by default, but I think that makes userland code much more ugly. Regards Thomas Tom Worster wrote on 26.05.2016 18:44: > Hi Thomas, > > On the face of it, I'm not enthusiastic to introduce new magic numbers > (which would be false, 0, 0.0, "", and [], right?) that PHP assigns when > coercing a typed, uninitialized property read by a file in liberal mode. > > This is like taking the most confusing thing about 7.0's dual-mode, scalar > type declaration of function arguments and boosting the confusion power. I > would want a new name for this complement-of-strict mode. "Weak" and > "liberal" don't quite do it. Promiscuous mode? ;) > > Tom > > > On 5/26/16, 10:40 AM, "Thomas Bley" wrote: > >>I think strict_types=1 should give a fatal error for accessing >>non-initialized typed properties, instead of notice. >>Example: >> >>declare(strict_types=1); >> >>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); // Fatal error, uninitialized... >>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); // Fatal error, uninitialized... >>var_dump($a->u); // Fatal error, uninitialized... >>var_dump($a->v); // Fatal error, uninitialized... >>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 >> >>Tom Worster wrote on 26.05.2016 15:53: >> >>> On 5/25/16 5:52 PM, Thomas Bley wrote: >>>> 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 >>> >>> Is the file containing these examples in liberal mode? >>> >>> What changes if declare(strict_types=1) precedes $a = new A;? >>> >>> Tom >>> >> > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >