Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103189 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91864 invoked from network); 20 Sep 2018 01:24:05 -0000 Received: from unknown (HELO mail-io1-f45.google.com) (209.85.166.45) by pb1.pair.com with SMTP; 20 Sep 2018 01:24:05 -0000 Received: by mail-io1-f45.google.com with SMTP id q5-v6so5732552iop.3 for ; Wed, 19 Sep 2018 14:30:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nH7C2d2KKAyJ9CT8evq3v0M88glY5O3mSU3bv9CeoCk=; b=vCmURJPOMiVT61PHBn0u0NYaf3U/uGgjtSK0uRkL8TkO5ja5pFDDMJuEqVF9SZCgxt JQorl7DXs244dix/9M2Lq2c4MEVLk4HHpexat6CTNx8icONGOYAY+epbIhUGcAtLv2Fe dtZ2IenVwLO+B1TFQsxg2vtNes/KWfWxkEyQa4JTjchkpHlkeT0xzPxhtIrpoww8LG6Q 9kgdEsiRFPBNjgDK1smX0rFvM0tQJqxzrmHALej+7RKMgZ9GlcrDYpOFWdArwtMbvsbm fqHqsOZoujNWRFuHeWYneBOVnptKi2lzLwDWn64RdVvM9yQp81jDn5zCWJ2g9u3Zza0/ rFDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nH7C2d2KKAyJ9CT8evq3v0M88glY5O3mSU3bv9CeoCk=; b=Du9yhalD0zNkEQXVDTN5/t8Ml7rRR+UkfE00bo/k/G5YRh+dSgjzIAvStGxlfJczv4 M3lhmzHa3CwbvaUI7E3v3srLFpV4WM4QXvBW+X9lzTVE696DRv4ApfpjAkYamicPOFHN sNfJoH+pUr5/Jum6V3K+Ict0PYq7IQjrf7cDVw9bb00900G4JL0mEJX7+VxhoqjMeKZk 7r8qQkf3j0Z4fVhfQwVEh9D00juP1fnAutjnkSPKZSsN9T/I4DRZ+3QvzoZTBQ9kpMee S7OEqqGawrGoIobxxbpNDJHFSVaJnaP+FaKLrKYRxLDho8hg15bXDAEAJTWqf2AF610b F7Jg== X-Gm-Message-State: APzg51ARTpmqFpZVhlZgFKKIWwpBr4vGQKMKmKOBAeBXcU8tw2ocnUpw BxTpUTo7mxi7TrC9mcVqY8Z/aL+wo8IoqbB3sIo= X-Google-Smtp-Source: ANB0VdYHbYr3bzxmWAggrPjVrFkhQZ4Pb3iVP9ug/xkYYo1qgRcydd2QGgwAU6uUOqpZWyBcmnVQzoN7q/mIMP7XVw4= X-Received: by 2002:a6b:b305:: with SMTP id c5-v6mr31024472iof.49.1537392632972; Wed, 19 Sep 2018 14:30:32 -0700 (PDT) MIME-Version: 1.0 References: <239cea65-a832-29a5-11e5-ee721e3bd957@gmail.com> In-Reply-To: <239cea65-a832-29a5-11e5-ee721e3bd957@gmail.com> Date: Wed, 19 Sep 2018 23:30:20 +0200 Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000c4cc8a0576401d5b" Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: ocramius@gmail.com (Marco Pivetta) --000000000000c4cc8a0576401d5b Content-Type: text/plain; charset="UTF-8" On Wed, Sep 19, 2018 at 11:17 PM Rowan Collins wrote: > On 19/09/2018 21:04, Levi Morrison wrote: > > I think this code should be allowed: > > > > class User { > > public int $id; > > public string $preferred_name; > > public string $username; > > } > > Why? What contract is being enforced by that class that is not enforced > by this class? > > class User { > public ?int $id=null; > public ?string $preferred_name=null; > public ?string $username=null; > } > > Both require the consumer of the class to trust that someone, somewhere, > has initialised the fields (and not subsequently unset them). > > Or have I misunderstood what you intended with that example? > > Regards, > > -- > Rowan Collins > [IMSoP] > 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. And yes, constructing an object without going through its constructor is quite common anyway - this was indeed part of the upfront discussion, and is also part of why I gave a +1 to the current RFC. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --000000000000c4cc8a0576401d5b--