Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111026 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34847 invoked from network); 15 Jul 2020 18:02:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jul 2020 18:02:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4711718054D for ; Wed, 15 Jul 2020 09:55:24 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, RDNS_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (unknown [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 15 Jul 2020 09:55:23 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id C0D46B4A for ; Wed, 15 Jul 2020 12:55:12 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Wed, 15 Jul 2020 12:55:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=GyNbmG l9E1M4j+D7ZTE42DVLlDObZFDeeqF6B4awwKY=; b=GFsfkUH5IMwRgHvq3G3kJh R/RuGT1y933PXaUbnAuvSL26GHi7nDZRHvQSyf6OtB3n8rUA5c42ARySPB7GlVUd 5CPak6HDR+ic7zEBKyDgGMjh6V+D2okfYRJB2QvKOj0pgHtYAow2Ah7XRY2HPZSy dEbH5e/jRl6xPEeVi9pkEDG5D6PGtGXivgUUhlqHMfC4dEABNzG9JukNtADhrDua DudCwuxsImyOLtULAvw0iU5nlvFPnfKmgH2HJwUbcDeQz9yth1aJ5/VFFYDh3su8 yLY2JcSKglc4oFuv7CzOpivJDrYBOj0FHyKZxlftbcrb09DiBxwb+UXPOHrwWK0Q == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrfedvgdduudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id E46BA14200A2; Wed, 15 Jul 2020 12:55:11 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-dev0-613-g8a73ad6-fm-20200709.001-g8a73ad6e Mime-Version: 1.0 Message-ID: <2d0fea79-0729-4cce-8b3a-be834614f242@www.fastmail.com> In-Reply-To: References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> Date: Wed, 15 Jul 2020 11:54:36 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jul 15, 2020, at 11:43 AM, Marco Pivetta wrote: > Hey Larry, > > On Wed, Jul 15, 2020 at 5:32 PM Larry Garfield > wrote: > > > 1) return null, which is a non-type, and thus you need to make the return > > type ?User or User|null, which means the caller *must* always check it's > > nullness. > > > > Allowing an object to falsify itself is a 4th, more type-safe option. It > > lets you return an object that both fails a boolean check (like null) but > > also has default values in it for the base case. A user object likely > > wouldn't use that, but a value object like an Address very well could. > > > > Until we can support for-reals monads (which would require enums and > > generics to do properly; the former is possible the latter is very hard), > > it's the best option we have for more type-safe returns. > > > > Adding a "falsey" state for code that expects `is_object($foo) === (bool) > $foo` seems to be a massive BC break to me, and reduces type safety of > boolean operators (and checks) by expanding the `object` type and all > operators and expressions that can interact with it. > > In general, `?T` is very much equivalent to `Maybe T` I disagree entirely. The value of a Maybe over just null is 1) You can bind to it even if the result is empty; the "if is null" check gets abstracted away from the main code. 2) You are forced to unwrap/extract the value if you're not just binding, which makes it less likely you'll forget to check if it's null. --Larry Garfield