Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103192 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59073 invoked from network); 20 Sep 2018 10:00:28 -0000 Received: from unknown (HELO office.int.leonex.de) (80.87.119.34) by pb1.pair.com with SMTP; 20 Sep 2018 10:00:28 -0000 Received: from ex-srv1.ameusgmbh.intern ([2001:678:4a8:100::ca11:112]:27755 helo=owa.int.leonex.de) by office.int.leonex.de with esmtps (TLSv1.2:AES256-SHA256:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1g2s73-0005nM-36; Thu, 20 Sep 2018 08:06:54 +0200 Received: from ex-srv1.ameusgmbh.intern (2001:678:4a8:100::ca11:112) by ex-srv1.ameusgmbh.intern (2001:678:4a8:100::ca11:112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1531.3; Thu, 20 Sep 2018 08:06:50 +0200 Received: from ex-srv1.ameusgmbh.intern ([fe80::38fc:4042:690c:8aec]) by ex-srv1.ameusgmbh.intern ([fe80::38fc:4042:690c:8aec%12]) with mapi id 15.01.1531.004; Thu, 20 Sep 2018 08:06:50 +0200 X-CTCH-RefID: str=0001.0A0C0203.5BA338FE.0012,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 To: Rowan Collins , PHP Internals List Thread-Topic: [PHP-DEV] [RFC] [VOTE] Typed properties v2 Thread-Index: AdRQp96/B0Jv26t/gUu/Ri7Q725wuA== Date: Thu, 20 Sep 2018 06:06:50 +0000 Message-ID: <2ba6ee5b25f941239aa32ff5f56f1396@leonex.de> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.222.37] x-ci-mailpolicy-key: 84cb5d25433c5992ed3bade71cea7bdf;c636fff3-b4f5-4f19-98fd-782e46d94a60;EX-SRV1 Content-Type: multipart/alternative; boundary="_000_2ba6ee5b25f941239aa32ff5f56f1396leonexde_" MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: Christian.Stoller@leonex.de (Christian Stoller) --_000_2ba6ee5b25f941239aa32ff5f56f1396leonexde_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable > -----Urspr=FCngliche Nachricht----- > Von: Rowan Collins > Gesendet: Mittwoch, 19. September 2018 23:47 > An: PHP Internals List > Betreff: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 > > On 19/09/2018 22:30, Marco Pivetta wrote: > > > > At least the approach without nullable properties will lead to a > > Throwable when a read is attempted on an uninitialized object, which > > is still better than nullability checks all over the place. > > > Is it? Doesn't it just mean writing this: > > try { > someFunction($object->propertyThatClaimsToBeNonNullable); > } catch ( TypeError $e ) { > ... > } > > Instead of this: > > if ( ! is_null($object->propertyThatClaimsToBeNonNullable) ) { > someFunction($object->propertyThatClaimsToBeNonNullable); > } else { > ... > } > > For that matter, all I need to do is define someFunction as taking a > non-nullable parameter, and I get the TypeError either way. > > Surely the point of a non-nullable property shouldn't be "it gives a > slightly different error if it's not set", it should be "you don't have > to worry about this not being set, because the language will enforce > that somewhere". (And to cover your last point, that somewhere doesn't > need to be the constructor, if requiring that is really such a big proble= m.) > > Regards, > > -- > Rowan Collins > [IMSoP] > Just an idea: If an object is initialized without having all non-nullable p= roperties initialized, one could store the instantiation place, and give th= is hint if an uninitialized property is accessed later. Example: // User.php class User { public Group $group; } // functions.php function initUser() { $user =3D new User(); // store this line and filename internally, because U= ser::$group is uninitialized return $user; } // index.php $user =3D initUser(); echo $user->group->name; // Throws TypeError informing about access on unin= itialized property and that it was initialized in file functions.php at lin= e 3. The TypeError still occurs but it makes it easy to find and fix the issue. = And the same could be done with unsetting - save the place where an non-nul= lable property has been unsetted and inform the user where it happened if t= he unsetted property is accessed. Best regards Mit freundlichen Gr=FC=DFen aus Paderborn Christian Stoller Web-Entwicklung LEONEX Internet GmbH Technologiepark 6 33100 Paderborn Tel: +49 (5251) 4142-526 Fax: +49 (5251) 4142-501 HRB 8694 AG Paderborn Gesch=E4ftsf=FChrer: Stephan Winter ________________________________ LEONEX ist umgezogen: Bitte beachten Sie unsere neue Adresse sowie unsere n= euen Rufnummern. Wann d=FCrfen wir Sie in unsere neuen R=E4umlichkeiten einladen? ________________________________ --_000_2ba6ee5b25f941239aa32ff5f56f1396leonexde_--