Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103191 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97969 invoked from network); 20 Sep 2018 01:52:14 -0000 Received: from unknown (HELO mail-it0-f49.google.com) (209.85.214.49) by pb1.pair.com with SMTP; 20 Sep 2018 01:52:14 -0000 Received: by mail-it0-f49.google.com with SMTP id h20-v6so9797690itf.2 for ; Wed, 19 Sep 2018 14:58:42 -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=Lv6K0bWMcgHuq8MzsUo9Rht3Qn/Pmf1fBluZ181dIT4=; b=KQhyuWE10Wq1FUlXlW1uQyj8WBZ/9/LHMBIpNWd+U+1fUgbT18JY96JAqHtYaohNlH voc5xrPl9ugFHQ8yvYL2X02HDfPkKfpyU0JhU36hUi6XTJaSZZyN1T3KDuThdzP/KjoK NLL3l75BD83JJM1YqjB4dgB2RKAWPjhRfhhIblSBBTuEiISO+hUCs9Rc6EGOJUQOC0Ka QZE1dvCM180dLXu8bIzSPfXNqswCSevC84YZK83h8MA3FfXBz5alAgkkz4F2d+Pxlh89 /08SQ+j9EQ/zO97qE145GMrPptMOFrM5qFyfLVLoJ2mtdThFM0DfsP/iV2KdczCCGoGb gFLw== 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=Lv6K0bWMcgHuq8MzsUo9Rht3Qn/Pmf1fBluZ181dIT4=; b=HqiMl7H4bJpWE6pElHy/7NUVi9k8Mp2gFD8FsC4QfGZfseuCDHP9ZSOW64jF5LS79V vt4B36H54lZZTaEi/QBBD+FrzFX4O8mE/gUSIKXzkCcTIImdoMuobdq9E3X03ASL4usl JPhdwi5ARZFNlFgfrSUwQSO4kYa/lmcS/3Nv+04r3pMKRmpnPMDpQVHFda4fKQoQKoB6 0u06yyb+PqO0RpeVkDfQEEJP8Gly6mUlD1k+Rcy5DAuxF50mj8HMq/rw86+Vdq5T8oAh aRNDIcVIXYUC7icF6K42FBZCSMJ9AEBZO2d//u7AYGWMuqsnzZ+s5LjckELL88HuVqBQ /7/A== X-Gm-Message-State: APzg51AZXUTDd4NUeDNpYFgfkaSYhIXUfAGp+W3oFfBjA6dSsVs1yDEI NXCp6QHxf6qV10Qrpo6ZX68L2COW0pAUdIwETWI= X-Google-Smtp-Source: ANB0Vdb2oQbMnKk8Bpr+LHrPqIqZU3rCb+B0bmdzMgsI3s9lSfD2Uv2r7aY9FrNdZ9n4Lr9JlMUrdtbMF889FiUpKqk= X-Received: by 2002:a24:f68c:: with SMTP id u134-v6mr1242316ith.17.1537394321806; Wed, 19 Sep 2018 14:58:41 -0700 (PDT) MIME-Version: 1.0 References: <239cea65-a832-29a5-11e5-ee721e3bd957@gmail.com> <88ff7632-7659-2f77-bb4c-20d32db178d8@gmail.com> In-Reply-To: <88ff7632-7659-2f77-bb4c-20d32db178d8@gmail.com> Date: Wed, 19 Sep 2018 23:58:29 +0200 Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000006e59b405764082bd" Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: ocramius@gmail.com (Marco Pivetta) --0000000000006e59b405764082bd Content-Type: text/plain; charset="UTF-8" On Wed, Sep 19, 2018 at 11:46 PM Rowan Collins wrote: > 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 > problem.) > > Regards, > > -- > Rowan Collins > [IMSoP] > That's what static analysis is for (see a bit above). Sadly, static analysis doesn't really fit the engine out of the box, as PHP is a bit too dynamic for that, and it doesn't really consider cross-file declared symbols anyway. Still, tools like PHPStan or Psalm can easily aid with that. Also, there are scenarios (discussed in typed properties v1) that make the uninitialized state actually favorable (every serializer ever, like every one, really). Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --0000000000006e59b405764082bd--