Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91698 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11734 invoked from network); 16 Mar 2016 17:27:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2016 17:27:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=t.carnage@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=t.carnage@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.43 as permitted sender) X-PHP-List-Original-Sender: t.carnage@gmail.com X-Host-Fingerprint: 209.85.215.43 mail-lf0-f43.google.com Received: from [209.85.215.43] ([209.85.215.43:33108] helo=mail-lf0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/98-48430-D9799E65 for ; Wed, 16 Mar 2016 12:27:58 -0500 Received: by mail-lf0-f43.google.com with SMTP id h198so24478711lfh.0 for ; Wed, 16 Mar 2016 10:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=A3ViYgjZUACB5HL1u9UleD8qdRtGWRwr8K8CaQ6AAcw=; b=ptRuJC9DzgQ2gb8LcCe7RGib89jijlVS3NgBiOQDfFfzo7Z6qJfDdgoLhxB0caFUNH fGoRxWAzqP/wEhRGfgqe3BDf3VP8kENd6kQNnEBhn2Se1SmPzZ6JDAUXN6TZ3+C8CoTw tUpN1Oqxyi8Rh9zeig3Ma26A5G4iKCCorWVJ+5Cp4Yab7rvqg+PLKoq+2cUPhQdyjPzP cepJqc05V3U/GgucVv07F5cDY2HD5rp4lL/fUXXC/YkwVenFrc/jnjGDLVMlydF4TNos W68TrnVCJ4KY/KUPjHPilDeYGy5vIdJ5HLdTi4+tl8TanT2ie+Ebc5nEZAcTAuzlElUh sQfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=A3ViYgjZUACB5HL1u9UleD8qdRtGWRwr8K8CaQ6AAcw=; b=Bptw4/r19fsPubVYkHmP4jqjKq+CQ6Tj4Rlu9GNNmu38bjsE2Kf3Ue3UIuNQSClXHV umH1jb+iIGuenAtZ5avZ8Hej4mOkzSm2vPbiqt4U3fLzKEFs2A5NXsk8Ki2tTK5lVH9u X2b62ma8J4UMCEhexlWkysQux3SKSGYuEPmSd4YwBEpRBRtmiXpcEHRwMrH7dsCZ0ide 8nNW3c8AHN8Nu6NuDsqOxkdHGjbxqmGb2Z2FpdPDuFpA5rrgF8s6xTW9fNDvcyurdsRp I+I7VdNxjDrZoXVteG1SZqjSCIJZscRVmsRqVA7d8tOKkLsFZONvphGlZG7Yr/y9uPze 5M2A== X-Gm-Message-State: AD7BkJLaTznqiGzNaSkABn9FwZNWRPsz7NvCpJcIjC3iDelB/lvzU1Aw5l0OZhQamR+Ud05S2aT+Jzh43eFeUw== MIME-Version: 1.0 X-Received: by 10.25.40.81 with SMTP id o78mr1619396lfo.22.1458149275159; Wed, 16 Mar 2016 10:27:55 -0700 (PDT) Received: by 10.112.0.200 with HTTP; Wed, 16 Mar 2016 10:27:55 -0700 (PDT) In-Reply-To: References: Date: Wed, 16 Mar 2016 17:27:55 +0000 Message-ID: To: Bob Weinand Cc: Phil Sturgeon , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11410bb69352de052e2dd508 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: t.carnage@gmail.com (Chris Riley) --001a11410bb69352de052e2dd508 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 16 March 2016 at 17:17, Bob Weinand wrote: > Hey, thank you both for investing your time :-) > Property types are definitely interesting. > > > Am 16.03.2016 um 17:36 schrieb Phil Sturgeon : > > > > Hello everyone, > > > > I have completed the draft for an RFC, to add Typed Properties. The > > patch has been written by the one and only Joe Watkins. > > > > https://wiki.php.net/rfc/typed-properties > > > > I would really appreciate constructive feedback on this RFC, with a > > few areas especially: > > > > 1. How scared are we that integers can be expanded to floats on runtime= ? > > This IMHO is quite necessary, for the same reasons why we even allow int > to float widening with strict return types. > > class foo { > float $bar; > function __construct(int $x) { > assert($x > 0); > $this->bar =3D 10 / $x; > } > } > > This is perfectly innocuous, but will fail for values 1, 2, 5 and 10, if > we don't allow widening. > Depending on the values it might also be not caught in testing. > > > 2. This whole temporary nullability situation, where unset properties > > will error on attempted usage if not set. Should they instead error > > after the constructor has been called if they are still not holding a > > value? > > Erroring when using the unset property is the way to go. > > The example from the RFC is showing exactly why... > > class Foo { > public int $foo; > } > $foo =3D new Foo(); > echo $foo->foo; // Patch currently errors here > > With one property, not so much an issue, we could force a constructor. > But with 20 properties, definitely an issue. > > If we'd error after constructor call, there are also other complications= =E2=80=A6 > > class Foo { > public int $bar; > function __construct() { > global $foo; > $foo =3D $this; > } > } > try { > new Foo; > } catch (Error $e) {} > var_dump($foo->bar); // not set, but instance is referenced > > Sure, we could find ways to circumvent that and change the class to > totally non-functional and making every usage of it throw an Error, but i= t > isn't quite elegant. > > > 3. Weak vs Strict. Right now this is entirely strict, with no > > declare() to change mode. Reasons for this vary, from various sources, > > but include "Not sure how to implement it" and "Well people should not > > be using properties as part of their public API". > > > > Help on 3 would be appreciated. > > Now, if we already have int to float widening (which I recommend), we > anyway need to do certain checks. > At that point we can just as well add weak typing, because, why not? > > We do not have an exceptional handling for return types (which are even > more subject to be strict-only as it is function-local =E2=80=94 properti= es may be > public). And so we shouldn't have either for property types. > > Thus, my recommendation is to be consistent regarding strict and weak > typing regarding argument and return types. > > > Also let's please avoid "PHP IS TURNING INTO JAVA" and the other > > rather common rhetoric. Strict Type Hinting might have been seen as a > > battleground for fans of strict and fans of weak to fight through a > > keyboard, but this RFC will not be the repeat. > > > > We'll have a nice, orderly, constructive conversation about this RFC, > > and improve the patch as you all provide feedback. > > > > Let me know what you think folks! > > Thanks, > Bob > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > I'm not 100% convinced that we need this now we have full type hint support for parameters and return types; but it does have potential to remove boiler plate for public properties. For point 2 nullable properties, how about some syntax which allows for a property to be null, or for it to be a specific type. I'd suggest a null assignment to fall in line with parameter type hints eg: class Foo { protected int $bar =3D null; //can be null private stdClass $baz; //can't be null } --001a11410bb69352de052e2dd508--