Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102860 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16481 invoked from network); 16 Jul 2018 16:51:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2018 16:51:30 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.53 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.214.53 mail-it0-f53.google.com Received: from [209.85.214.53] ([209.85.214.53:53462] helo=mail-it0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/5F-39793-F0DCC4B5 for ; Mon, 16 Jul 2018 12:51:29 -0400 Received: by mail-it0-f53.google.com with SMTP id 72-v6so5653409itw.3 for ; Mon, 16 Jul 2018 09:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OkidxWyNWKWSFe0+LsTYqKIahzUXKYCK+C+3NOWz+x4=; b=DVOoY91mmrSPR28uwJcACa0Wl6Br+C7mzCEAnRpobX/I2uBYSGArdVW6vRqR1pT7/i 1XK1CB7HU8zaOOCe3p1IqvcSAFHi3gUrQXySx0nbX8adtU8pmC7ssUnUsYhPGYhO3B8a ZL8WoUzt81EgswCGT+NyQ6vmMGD/y6oJdD/SUwmnsuRiWH/gQ0PhsMa8db2ijU7BRpLo OFByJnug5sMHaFhZMnv3Q9FXW9ZFnSHFG++Xdm+BBYZiL49zR4IucH2GVaQh/O2/+GfJ 1pj4I+HKAuIMzQkQMSAuQnz9A8MIwnpT5bQy1WO1CIz+vOKrvnNBpRkKUXVwEwJgt1Le 3H7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=OkidxWyNWKWSFe0+LsTYqKIahzUXKYCK+C+3NOWz+x4=; b=FqIRLeH+MFgaG1WyMUxM1ac0mrxd927R+u9XxAr+wiTQ2pl6LISiFf5RzYjG31iWLv vhG40WNKDLNoR19UStTJKC0uWNXev9Iofx9VUkkcMHC+YWO6Eqjpt1agRFA86KURuAsH Muk8irYIie1hiy2EZbZqxIX0L3KhxdPIMp3BEfk/yRbXz7IA1HP+epZQKrCUV3Y55jfL RojvPalVWGWjZaGPD7QgUisSKbbYJkIdWBjsNyXRMb2MUQyazvG50CLdgacaywTLXTbf oK0rqDq8eU1jQPXYzBPU4MZiSdloUEzTrakhND8Y5IJilM/dCkXqyI0lvwiZoRKV274j p/cQ== X-Gm-Message-State: AOUpUlGxz9m0loMVxjBSJWCNX5FmLxJySP30ar9V9OTuhX4lvYEfrDGe NUe2A7hUDiwmpVkJISkWJmsJgUlzh3quGSspryE= X-Google-Smtp-Source: AAOMgpdW6DCtXSUktrhqIQSVEphPtlcHBe2Dij0pfw/KCcWTkxJDmU8vg8JS1T20OYAq4HB5MT2LlZJ+tHlxOGAyLoY= X-Received: by 2002:a02:8c75:: with SMTP id j50-v6mr15150935jal.76.1531759885262; Mon, 16 Jul 2018 09:51:25 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:95a8:0:0:0:0:0 with HTTP; Mon, 16 Jul 2018 09:51:24 -0700 (PDT) In-Reply-To: References: <8916EC21-D368-40F8-9ABD-CE0C04A73539@gmail.com> Date: Mon, 16 Jul 2018 17:51:24 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000d7a6ba057120a318" Subject: Re: [PHP-DEV] Non-nullable properties From: rowan.collins@gmail.com (Rowan Collins) --000000000000d7a6ba057120a318 Content-Type: text/plain; charset="UTF-8" On 16 July 2018 at 17:20, Nikita Popov wrote: > On Sat, Jul 14, 2018 at 3:09 PM, Rowan Collins > wrote: > > If I have an instance $v of that class, I would expect to be able to >> safely call $v->validFrom->getTimestamp(), but need to check for nulls >> before doing the same with validTo. Under the current proposal, doing so >> will risk errors, so I will have to check both properties before access >> anyway. Worse, using is_null() or ?: will attempt to retrieve the value, so >> I actually have to be *more* careful, and use isset() or ?? instead. >> > > I'm just going to reply to this one line, because this is the root of your > misunderstanding: > > The user should never, ever, under any circumstances (*) check for the > initialization of a typed property. > Agreed. Which is why the language should guarantee that they don't need to. > The user simply uses the property under the firm knowledge that it will be > initialized -- or there is a bug in the initialization code. If there is a > bug in the initialization code then it needs to be fixed there, not by > introducing a check when working with the object. > Absolutely. But in order for that to happen, the error needs to be shown to the author of that code, not to some downstream user who will have no way to fix it. As I mentioned before, I see no practical difference between seeing this comment in a library... /** * You can rely on this property being initialised to a non-null value in the constructor */ public ?Foo $foo = null; ... and seeing this declaration under the current proposal ... public Foo $foo; In both cases, as the user of the library, I'm entirely at the mercy of the library author to implement the documented behaviour. If I trust them, and use the property without checking it, I risk errors if they have made a mistake, which I can't fix. > > Please do also remember that uninitialized properties and unset properties > are the same thing > No they're not, an unset property doesn't raise an error when you try to access it; see my last e-mail to Marco. Regards, -- Rowan Collins [IMSoP] --000000000000d7a6ba057120a318--