Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110955 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 127 invoked from network); 11 Jul 2020 21:11:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 21:11:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1615218054B for ; Sat, 11 Jul 2020 13:02:58 -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=0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (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 ; Sat, 11 Jul 2020 13:02:57 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0E5195C00C3 for ; Sat, 11 Jul 2020 16:02:57 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Sat, 11 Jul 2020 16:02:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding: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=5yDzt47nqTsS0ti8ojMlpqIqV7DJdLquPjmb9TDKp c0=; b=S6KfKOLH6RNbfFpG9z6eYwAHH5I+yt7TRKQ/y4mtytmyMJrKPCI3M1fri NdQQwG0QY0eXzV8De+KvheTcdCYZ6GoOu2gAJ25a4T3d2w7l09cAm6DpwZj5Held hxjLBbVtWiqzqlBdpRvb7ONrLu73QJNX8oNeWjbGVrg4Rg41gjRXAS6gZv8RmBfZ +YlOHqKlWUKvvTlXhgj9kT4VVvsW5J5k4Dl64RHM91jGv92Wm8D++pCY3xkx2L37 PoLoWz8EYaTG5soDV2pdvMZYlxJFmzefS1aZbSQ7pdQcTw0+41aWC24l3sZcF/7e nkwx6cN2Ua4zL78Xmaoe1MqNJUVUA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrvdefgddugeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne goufhushhpvggtthffohhmrghinhculdegledmnecujfgurhepofgfggfkjghffffhvffu tgfgsehtqhertderreejnecuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoe hlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhep ffejudejvdegffeuheetieejfeeigfekhfehgeetieejfffhveelgefgjeejjeeknecuff homhgrihhnpegsihhtrdhlhienucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id A97F814200A2; Sat, 11 Jul 2020 16:02:56 -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: In-Reply-To: <65EE4215-3F80-435C-B271-DBE30D26E2CB@joshbruce.dev> References: <65EE4215-3F80-435C-B271-DBE30D26E2CB@joshbruce.dev> Date: Sat, 11 Jul 2020 15:02:36 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [CONCEPT][DISCUSSION] Instance as boolean From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jul 8, 2020, at 11:39 AM, Josh Bruce wrote: > Link to working draft: https://bit.ly/php-0001 >=20 > Discussion on implementing a means by which a class instance can=20 > interacted with syntactically as a boolean. >=20 > At this point in the discuss the only means discussed is creation of a= =20 > method (magic or via an interface). >=20 > Ability to cast is not ruled out.=20 >=20 > And, my limited knowledge of PHP at this depth, much less under the=20= > hood, means there could be a lot of unknown unknowns regarding the way= s=20 > a boolean can be interpreted and interacted with; therefore, those may= =20 > not be covered at this time. >=20 > I=E2=80=99m also not liking the overly contrived nature of the samples= and will=20 > improve those over time should interest maintain or increase. >=20 > Cheers, > Josh >=20 > ps. If you have any feedback or information on social interactions her= e=20 > that might help, please do let me know, normally I would have watched=20= > for a while before putting my foot in - hopefully it doesn=E2=80=99t e= nd up in=20 > my mouth. :) Hi Josh. Your social interactions seem fine, no worries. :-) You may need to ask= for wiki access; the configuration/rules around it are, honestly, kinda= weird. To the RFC itself, as you've likely noticed you've stumbled into a long-= running contentious question. __toString() is itself already controvers= ial and some don't like it, while others want to see every possible prim= itive type added for completeness. Focusing on Bool is, I think, a good choice because it has an argument f= or it other than "well it works for strings." You hint at it in the wri= teup but really bury the lead: Null objects. Being able to not use null or false as a "not found" case and instead re= turn an "empty" value object is very nice, but then you also want to kno= w if the value returned is legitimate. An object that could self-cast t= o boolean makes something like this viable and type-safe: $user =3D $repo->getUserById(5); if ($user) { // Do stuff with user } else { // The user wasn't found. } No exception needed, no null, no false, just a safe "empty" user object;= whether you want to branch the logic based on that is then up to the ca= ller. It also allows an "empty" object to still have default values ins= ide it (like a username of "Anonymous" or something), which are up to th= e implementer. I'd say focus on that benefit. The similarity to __toString() is just t= o show that the implementation is consistent with existing patterns, not= an argument for adding _toBool() itself. Feel free to steal the user-r= epo example if you want. I have no strong feelings about interface vs. magic method, that's an ol= d race I don't have a horse in. --Larry Garfield