Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103221 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63781 invoked from network); 21 Sep 2018 19:19:04 -0000 Received: from unknown (HELO mail-pl1-f178.google.com) (209.85.214.178) by pb1.pair.com with SMTP; 21 Sep 2018 19:19:04 -0000 Received: by mail-pl1-f178.google.com with SMTP id b97-v6so6139536plb.0 for ; Fri, 21 Sep 2018 08:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2aifKZNxy597k8sxwR3VTQNt/Fmy/tGykPontqFs7IM=; b=HH4fMmsU3W7LkD71qhqXil1GBD/sZ2xb178mWhjPXks7k7Q7cJCDYcvRPsAQwPxFU7 kVzJKsEhiYd1oazW+iYINiZRj31ohbgO6Az7C5CExWRtmKd93I9/Qr3Fd1w7BH/mMuN+ bbx+ob6xMKUrwIOJTtwEY+VLM4PkdYPPxn9hIFo5VwbqQm6fQBRJe5Hazz7LvB6MN8Q8 k6mPZ517Tt8137mK8oETYl/juTIwLEyncefyKMdDHtcZwx1FtJDmMlPeQ4qopBsJaQ25 AV+rODk54nbdr1yeIoC0smoEU+NXSS5Z/Pg/+6f8t4D9oe6G65wVayRK0xM9Ld+MUG4S MJDA== 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=2aifKZNxy597k8sxwR3VTQNt/Fmy/tGykPontqFs7IM=; b=ogh84T2/T79QNsiXnHmtqoGxrmJI0HNYruwKAhfG+7h9fVHwG6E2cXRqRsbKVEOVQq /vFgZwd+eoKBLXYngLHDtauGVUBJ2AU3TpEZJpmleJg+egdIG1CxHqlx+21CMCDXwxbx aZkryHssPPh6DZmDhYwlR2Cm1ArvAsLnsdvNGkdP+pHGkdtIQn+i4sBym+V+1OZsYns6 fyqffUhsilbbeXT9NJEDCMvOVob78RKqt18FlwtxkJoAMTBk/HPDhp2Wp9E4HyhZD1LA CmX/XyhWzwfTulH1j2Y0TLNDbAQl4zkjf7U6guT/XdDRogwvNLIkrTAlzyVNO2inZLyi 4LYA== X-Gm-Message-State: APzg51A6V6Mbcte7vfuSkgkYKRvIdNVjoan/KkPAUXU/AoQWvtx0dwM3 +vTRCRhVy5t+mYEDfhGztpgYmLPrrbmY5QIegxr6kfSO6nc= X-Google-Smtp-Source: ANB0VdbC/lmmZIJYiJncDXdZgr8CLzDkzJJ2Fgr/BMmvnKvfbDDPsMH23TldaCTfzi5kqKdJYAR6FCf7EbkNKyrDUM8= X-Received: by 2002:a17:902:7203:: with SMTP id ba3-v6mr45583741plb.179.1537543556939; Fri, 21 Sep 2018 08:25:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 21 Sep 2018 17:25:50 +0200 Message-ID: To: lester@lsces.co.uk Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: rasmus@mindplay.dk (Rasmus Schultz) On Fri, Sep 21, 2018 at 10:24 AM Lester Caine wrote: > Ignoring the debate on uninitialized/null ... not all objects ARE > invariant hence nullable types. > and there are very good reasons for not setting values for > everything, but it seems that these types of object are deemed to be > 'bad coding' where in fact the simply have elements that yet to be > 'initialized' if at all for this instance of the object. that's what nullable types are for. > The constructor > simply creates those elements that need to exit and does nothing with > the holders for elements that have yet to be populated ... they stay null. hence nullable types. the point of using type-hints on the properties of a class is to describe the invariant state of that class - if the state of an instance of that class is not what the class itself prescribed/promised at the time when you return from the constructor, what's the point? the only difference between using nullable vs non-nullable property type-hints then, is whether you can set them *back* to null after setting them to value - but it's okay for them to return from the constructor in a "null-like" state? this doesn't provide *any* additional guarantees: class Foo { public int $bar; } $foo = new Foo(); // invalid state allowed $foo->bar = 123; // valid state $foo->bar = null; // invalid state NOT allowed?! Have the effects on the null coalesce operator even been considered? $bar = $foo->bar ?? "what"; Is unintialized "null-like enough" or will this trigger an error? Extremely confusing. Type-annotations are essentially assertions about the state of a program - if you can't count on those assertions to be fulfilled (which you can't if they're not checked at the time of initialization) then they're not useful. The bottom line for me is that property type-hints were supposed to make my programs more predictable, make the language more reliable. Instead, we've introduced a whole new kind of uncertainties, new ways to write unpredictable code, a new kind of null that makes the language even more unreliable. In terms of reliability, it's actually sub-par to hand-written accessors. Shorter syntax, reflection support, great - but ultimately at the cost of reliability and predictable state. For one, what good is reflection, if it tells me I can expect a property to be an integer, and it turns out it doesn't have a value after all? If you want horrible code with no guarantees, there are plenty of ways to do that already - you don't need property type-hints for anything more than mere convenience in the first place.