Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93577 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77950 invoked from network); 26 May 2016 17:00:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2016 17:00:56 -0000 Authentication-Results: pb1.pair.com header.from=fsb@thefsb.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=fsb@thefsb.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain thefsb.org designates 173.203.187.67 as permitted sender) X-PHP-List-Original-Sender: fsb@thefsb.org X-Host-Fingerprint: 173.203.187.67 smtp67.iad3a.emailsrvr.com Linux 2.6 Received: from [173.203.187.67] ([173.203.187.67:36261] helo=smtp67.iad3a.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/8B-17600-7CB27475 for ; Thu, 26 May 2016 13:00:56 -0400 Received: from smtp25.relay.iad3a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp25.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id 9802F180274; Thu, 26 May 2016 13:00:53 -0400 (EDT) X-Auth-ID: fsb@thefsb.org Received: by smtp25.relay.iad3a.emailsrvr.com (Authenticated sender: fsb-AT-thefsb.org) with ESMTPSA id F0F701805B1; Thu, 26 May 2016 13:00:52 -0400 (EDT) X-Sender-Id: fsb@thefsb.org Received: from [10.0.1.2] (c-66-30-62-12.hsd1.ma.comcast.net [66.30.62.12]) (using TLSv1 with cipher DES-CBC3-SHA) by 0.0.0.0:465 (trex/5.5.4); Thu, 26 May 2016 13:00:53 -0400 User-Agent: Microsoft-MacOutlook/14.6.4.160422 Date: Thu, 26 May 2016 13:00:49 -0400 To: php-internals , Fleshgrinder Message-ID: Thread-Topic: [PHP-DEV] [RFC][Vote] Typed Properties References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> <871d57cd-cf8d-626c-8bfc-4c23482fb38d@fleshgrinder.com> In-Reply-To: <871d57cd-cf8d-626c-8bfc-4c23482fb38d@fleshgrinder.com> Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: fsb@thefsb.org (Tom Worster) On 5/26/16, 12:48 PM, "Fleshgrinder" wrote: >> >> Under another 5th option, the problem you state does not arise. Disallow >> "public int $x;". Under this option you may declare $x with type int and >> an initial value or you may declare $x without type but you may not >> declare $x with type (nullable or not) and undefined initial value. >> >> Tom >> > >This would be a valid approach too, yes. I personally would be against >it because I do not want to initialize all my properties. > > class A { > > private int $x; > > public function getX() { > if (empty($this->x)) { > $this->x = 42; > } > return $this->x; > } > > } > >This would not yield an E_NOTICE because both isset() and empty() never >do. This allows the attentive programmers to keep up there coding >practices without the necessity to assign meaningless values everywhere. > > class A { > > /** -1 is invalid */ > public int $x = -1; > > /** 'INVALID' is invalid but empty string is allowed */ > public string $s = 'INVALID'; > > /** Null byte is invalid but anything else is valid */ > public string $welcome_to_the_c_world = '\0'; > > } If you want that kind of thing, you can do it the old PHP way like this class A { private ?int $x = null; ... Tom