Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110970 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9389 invoked from network); 13 Jul 2020 11:27:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jul 2020 11:27:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C379F1804DB for ; Mon, 13 Jul 2020 03:19:51 -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-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 ; Mon, 13 Jul 2020 03:19:51 -0700 (PDT) Received: by mail-lf1-f41.google.com with SMTP id d21so8557216lfb.6 for ; Mon, 13 Jul 2020 03:19:51 -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=gs0UhrmDBxwwveX+1Is6s7HeFTr450pnrVWINihWfhE=; b=IlGobQIoFJmsxzTpnprJJw7und0sJEmy4ShlXkBYyUMBEgT++B1L9rZqyxCD5xpR2M NIWgHrbo5//fnFNfbwtTL8we/2CeccgLnI4rGlpymLdkIOm8gqH7KDTXyHXGDz3aDBHY umOy1ND7PKzF+vA/KfV4JkWPtk2MBGT1yEzm4fJq5j78V2IZDEW06pGSB0V+Rk3tYmq7 UrUBrzqoASb2Zc+MQpbd8pHl1gXloC0zDkPiKAzV4qsn+Qrxv8YSUCbZ1TbqARQ1q7LA 2fKSHtXol9vZiD1eCx1T6oRPxExIjGpuyVyrg8hSY7AevvdQ8Ov0YrehrO97/zlL3L3N EkiQ== 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=gs0UhrmDBxwwveX+1Is6s7HeFTr450pnrVWINihWfhE=; b=jCr3r67yHmyCIa3dk3nZCHnDVa4sy9NOm+HcKy1XxdIF75UiYjfWjL56W907uht2Qq 1DMfhvTIVaLEDlL4s811ALIDFTY5bBSy+4tNFrxxnOB6eRqNYEfEIOgAVSlUyr7hLVIl xIatGYDZDpAjs9kmZG4TebKp6lcmOgOmMaSTwO8KLQ4VFyEGL0XH//q55XhGX9tvywAP f+PQeZjWxVU5y6kJR4upYh9H7FAH3iwCajS7y88CJj+pbe3MiflqfazHgV1VfHaxhVKa d0MOoD3ol6Kj+a4EcE4hqmlZyc6xpRr5RzOviaFoNlQJna7WNcCsuVjOF90H6K3Kz4oz zEjg== X-Gm-Message-State: AOAM531wzBFKvVGB8BJsMYY/q9lV5pPbZhy3QfS9QaNY879Hs0aDEEPq retNokJ6I8QBQDmZOgdDEZxjg4tm6V0VOqU2Llp21UBDhRQ= X-Google-Smtp-Source: ABdhPJwuxl7JGyCFITR5yd1eGEQam39abV74Vfdq4RQmQNhu8PfMyHJNyB0qmI0E8VSle+qI3z1rCH1iE/72xo/Hric= X-Received: by 2002:a19:ad41:: with SMTP id s1mr36407977lfd.191.1594635584504; Mon, 13 Jul 2020 03:19:44 -0700 (PDT) MIME-Version: 1.0 References: <7238EFA9-8BE4-48E2-B6C6-6C3E14CFA208@joshbruce.dev> In-Reply-To: <7238EFA9-8BE4-48E2-B6C6-6C3E14CFA208@joshbruce.dev> Date: Mon, 13 Jul 2020 12:19:28 +0200 Message-ID: To: Josh Bruce Cc: php internals Content-Type: multipart/alternative; boundary="0000000000008f875905aa50076e" Subject: Re: [PHP-DEV] [CONCEPT][DISCUSSION] Allow objects to declare emptiness and by extension truthiness From: nikita.ppv@gmail.com (Nikita Popov) --0000000000008f875905aa50076e Content-Type: text/plain; charset="UTF-8" On Sun, Jul 12, 2020 at 7:49 PM Josh Bruce wrote: > Latest version as we zero in on what this is really about: > https://bit.ly/php-0002 > > Other threads: > > 1. https://externals.io/message/110879 < > https://externals.io/message/110879> > 2. https://externals.io/message/110881 < > https://externals.io/message/110881> > > Thanks for all the feedback so far! Definitely feels like progress. I have a really hard time understanding what is actually being proposed here. You mention the introduction of the Emptiable interface, but not how it influences empty() or (bool) casts. There's some examples in "Usage" that are possibly intended to illustrate this -- I suspect that a "return true" vs "return false" mixup has made them impossible to understand though. Some thoughts on the general domain: 1. I don't like the idea of decoupling empty() and (bool). empty($x) is currently the same as !$x (modulo notices), and changing that will make PHP's already messy implicit type conversion matrix even messier. 2. Coupling boolean casts to an "emptiness" concept seems somewhat dubious to me. That works for container structures, but what about something like new Bigint(0)? It would be quite odd to declare an integer "empty" to make it evaluate to false. 3. I'm generally not a fan of overloadable bool casts. We have exactly one object with an overloaded bool cast in PHP, and that's SimpleXMLElement. As far as I know, this has only caused issues. A big reason for that is that using "if ($foo->bar)" is a common idiom for checking "if ($foo->bar !== null)" -- one that works very reliably, with the exception of SimpleXMLElement. 4. I think if ($container->isEmpty()) is much clearer than if ($container) -- why would we want people to use the latter instead? Regards, Nikita --0000000000008f875905aa50076e--