Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111020 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8913 invoked from network); 15 Jul 2020 15:32:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jul 2020 15:32:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E64D41804D2 for ; Wed, 15 Jul 2020 07:24:53 -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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 15 Jul 2020 07:24:53 -0700 (PDT) Received: by mail-oi1-f181.google.com with SMTP id h17so2342673oie.3 for ; Wed, 15 Jul 2020 07:24:53 -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=puU/x2JBTG2cz4MLBUyJSnXv3mw0m2gxSGMR5Gi0mAE=; b=B7SxpPjN2CSkLH6p3i+llOnPvTQTYnbjCBCMb9mov6oHjKDeJxznCYjqPKL68Ve3V4 cfTwLnmasirGT9dPlItd7lBa86eqfZnszGEoe2hPlR2TgqKQyM0yBo/38lvWku4+W8au sAMJzBp2SjnU/8fZ+iu67uNBJR+ZBf+UkY+qlAW3bnT31AegTJBDpG6D4f9ckHsK3wu7 +2mQWbOQWmz69cEazFO5gthfSuzaxCR6UExgGTKJpS6j4dR3tjaq+ZH9w+m85iz7AF9b BZsnXCh19In/gQpLEOS2ExQPvdPM5wATbpxK1JXgTFRhhjkyE9eDkY65RWH4tdNdZigS 0ElQ== 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=puU/x2JBTG2cz4MLBUyJSnXv3mw0m2gxSGMR5Gi0mAE=; b=WNwQkjHS4od7nMJyvfE/HsNzV2ts4qtIZIxNYuFP9TDjnyGqJKootoaDIEUsRr+Exu 9LJL8bomZYKMpJGJQXcbklbnAJcmVPtFliesa0OZnE364fG0KLfghK4IZ1P7u8M4Vfz7 I+8O7r3Rwdq2Shnqzh/XhzvduhXP0TLirlYjaX26/WnpXNCjn6jF5kUwdmqxkYmqsA/5 CA7Cz9dFt2S2QExDnHGBZwy2wT0+aUPZfJvwC1pT5o9pjKNaZISL/pkMYbG9DnhSjehf XicB5KzEPkSgkuPx8csHjEtn4Ze4A6BwgLPyl7Bvaowr/H1sdPM5EacKnqa/oF6IUXv0 3hWQ== X-Gm-Message-State: AOAM532XKYUBfjrBMFptzGicQbeDFwfGPysLM+zzT3cKzW99yM0OwXy7 KWfccaprZT5LbIA2GyQcfwbn8+4O+TAvH3otfW3jynjv X-Google-Smtp-Source: ABdhPJxqq2iwFWIr2ie2gr3drkGJddiU6sZUHQlwnTPcg1rbuO39Piu1WrGUctZ+JBv5oeLrAW83Nb5ohuzBBF0819Y= X-Received: by 2002:a05:6808:aa2:: with SMTP id r2mr7692475oij.162.1594823088257; Wed, 15 Jul 2020 07:24:48 -0700 (PDT) MIME-Version: 1.0 References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> In-Reply-To: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> Date: Wed, 15 Jul 2020 11:24:33 -0300 Message-ID: To: Josh Bruce Cc: php internals Content-Type: multipart/alternative; boundary="000000000000a7bde805aa7bafa9" Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: david.proweb@gmail.com (David Rodrigues) --000000000000a7bde805aa7bafa9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I really appreciate any effort that can make PHP a more powerful language. However, for this item, I believe it will generate much greater cognitive complexity for new users (and I hate to assume that this is a problem, but we have to remember our roots). Why, for now a variable $x will be truth, since it is an instance of an object, now it could be false, because it implements __toBool() and Falsiable interface in a "magic" way, making everything very confusing if the user is not aware of each class that he is instantiating (or even receiving from other places without much condition to know precisely what it is). For this type of situation, I still prefer the introduction of clearer methods that suggest the validation of your own properties, in order to make it much more flexible than simply returning a single "general" boolean by-instance. For example: isValid(). if ($entity?->isAdministrator()) { /** Entity is an administrator. */ } else if ($entity?->isModerator()) { /** Entity is a moderator. */ } else if ($entity) { /** Entity should be an user or similar. */ } else { /** Entity is not defined. */ } On the other hand, the implicity (bool) cast working together with __toBool() is a good one, but I think that it is being discussed in another topic. Atenciosamente, David Rodrigues Em ter., 14 de jul. de 2020 =C3=A0s 20:59, Josh Bruce escreveu: > Implement an interface and magic method to allow objects to represent > false (or empty) while still be valid instances of the custom object (typ= e). > > https://wiki.php.net/rfc/objects-can-be-falsifiable < > https://wiki.php.net/rfc/objects-can-be-falsifiable> > > If you saw the latest from this morning, not much has changed except > hopefully improved formatting and now being the official mix of things. > > If this is your first time, the cues are taken from: > > - __toString() > - Stringable > - and __toArray() (not accepted or approved yet) > > Thank you for all the feedback and patience so far, appreciate it! > > Cheers, > Josh --000000000000a7bde805aa7bafa9--