Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118938 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51533 invoked from network); 2 Nov 2022 08:12:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Nov 2022 08:12:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5E8701804F7 for ; Wed, 2 Nov 2022 01:12:31 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 2 Nov 2022 01:12:31 -0700 (PDT) Received: by mail-io1-f47.google.com with SMTP id z3so14402408iof.3 for ; Wed, 02 Nov 2022 01:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=GAiDurcKE0kyQUPgnFFeH5aiRRGBmbmWw9dq8y7gPHo=; b=UEH2cfrGVu3cbqWkVnLPaa/KLdv5t5NfhsUHMzVWbiiPpIsRbrtyC6kqDebl22iR3E 9dGrVb2cDaEbjwfHsGIAR8dnYTXGj2gng2qaj4N6x5Mq9TeIOVWNEGiNT94xrofFYsHI csVRUE4NgGYF3FxCvclM0YukIW//8hqPINBpPVMAEMPbjfQ3RuP6x5z65o/5euzc2m42 Jdd8dZC43Lz5qm2EGL4hSkAfsNoqdpkDQoUamTMcIBgXEwEcaCuHaUJbKkDJNpPvQifA BiXuU+Y8/KIz+9FaAfPrqmZ/K0uqwGKhi5HCu2zVyN8WWkk39xdA7AxwRBrBlSCXl/fS hlNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GAiDurcKE0kyQUPgnFFeH5aiRRGBmbmWw9dq8y7gPHo=; b=UxPYTZN7V8avBX/+T7ZJxYJdBSv8W1KJCCtzgF1/abO9pU1wCO6+TIB0iM51vtrfca 1skJCsm6Q1GctXmu5YS/yvIbWdopjO0w7h7t2gGx1VONv5EKQBtP3EQ66Aoui+rtpXCs bKlRIGpytupQ7t0Z0se4jBWc94xMj+HKVYx9bye1gXklGl9oBsWXN17NX3IXU+cFq96J aHVJJ/ZgYTWbauTPz01TE2fMQ17sLcwj9T6UArIJqCBtUMwmoGW03jYNQ5oRgkqyKKMT eqheug7KxWWypaey9NKvbGckOnjLeRfhDLfwi8bnjPo3ow2Z7f39WWEAaZKMIcEyQDE1 RToQ== X-Gm-Message-State: ACrzQf0PHX+0HoHRysz5OYDtqhJsRD0xFMuK26UzU1O+ccPmPTdD3vBR 4IHS1ywCUQtLyBFHfGkKaHQdSlX3AoKuObWa/Bs= X-Google-Smtp-Source: AMsMyM6oeVosUiPllyyDkrQlZnS/4SlK0robq30g7o1cBOdfqHsJKZcs0nBj1nmITs0xS+75g4LmYYrLin2pzu9Yc/A= X-Received: by 2002:a6b:5d14:0:b0:6c9:9d40:8dfd with SMTP id r20-20020a6b5d14000000b006c99d408dfdmr13825211iob.2.1667376749979; Wed, 02 Nov 2022 01:12:29 -0700 (PDT) MIME-Version: 1.0 References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> <1bc7759a-63b8-4b96-bb69-97b50f851307@www.fastmail.com> <94DC0839-E43B-4F3A-9105-8F3CB9D7BBC1@joshbruce.dev> In-Reply-To: Date: Wed, 2 Nov 2022 09:12:19 +0100 Message-ID: To: Josh Bruce Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e3aebf05ec786651" Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000e3aebf05ec786651 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Josh, pon., 31 pa=C5=BA 2022 o 20:38 Josh Bruce napisa=C5=82= (a): > Hello Interntals, > > Someone reached out to me outside of internals regarding the RFC I > submitted on being able to declare objects falsifiable, so, I decided to > update and re-enter the fray. > > I=E2=80=99ve updated the references section as many of the RFCs that were= under > discussion at the time have since been implemented. > > I still find myself in situations where having the capability would be > beneficial. Specifically, I=E2=80=99m noticing with API responses where I= want to > pass the body received from a ResponseInterface the object can check > itself. I currently use methods such as: > > ->isValid() > ->isInvalid() > ->toBool() > > And similar - the isValid and isInvalid() methods are just aliases of > toBool(), which speaks to the ability for adopters to make their interfac= es > compatible without breaking changes in their code. > > In the case of a conditional - looks like this: > > $obj =3D Object::init($response); > If ($obj->isValid()) { > // do something with $obj > } > > Or: > > If ( > $obj =3D Object::init($response) and > $obj->isValid() > ) { > // do something with $obj > } > > Would like to be able to do something like: > > If ($obj =3D Object::init($response)) { > // do something with $obj > } > > As of today, the last example is always true. You wouldn=E2=80=99t be abl= e to > create a guard clause for the negation: > > If ( > $obj =3D Object::init($response) and > $obj =3D=3D=3D false > ) { > // handle invalid object, which could include something like > $obj->failed() > } > Have you tried not initializing invalid objects? This could help you. Also that sounds more logical to me as I don't see any reasons to initialize invalid objects if it's a matter of simple validation instead. P.S. I don't see it feasible to have objects that evaluate false in logical expressions. Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000e3aebf05ec786651--