Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111031 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73893 invoked from network); 15 Jul 2020 22:45:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jul 2020 22:45:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EB98C1804F2 for ; Wed, 15 Jul 2020 14:38:42 -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,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, 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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.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 14:38:42 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id z24so4385825ljn.8 for ; Wed, 15 Jul 2020 14:38:42 -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=jM3/MAksrAuUkfY/cdbO4sQytP5erU/CziTY+Vf83SA=; b=DHDch/Eb/5/RNad8rGMO28yT0Vo9eUM4PFTaY81RJO2CvOrYPRsZhwfb4/2su4zHKr O6ojOwpvOnkYqidTsZ6JwIKIeZecNNR1tgotDiaUX+u+W7imu113OWH8PDQBEuD2kNNK cG2LMWmIQVLJxLC9SjwBRIXK9a2xSc1yzVQQ5Zhe2hEcD4Aaoq4t9yQ5MMjHTYmdgtHZ 2PfWncqsip5AgP1aCwI0uq4W2u7DVZi0EBJb9IX6L/9AzdttaDZQrD2aj9/iPdZ8GM02 tZRA7PmlRECFUhLxoQxk0vZQAjTgtXWDRcvovOYtukAqG0cf/Oh+vuHT8e4mQ/MhfktJ 84kg== 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=jM3/MAksrAuUkfY/cdbO4sQytP5erU/CziTY+Vf83SA=; b=UzeMPh3jnUsKDlb/xl+eb+f+1bdNq7pH+2Pcwl9OORYS41M6NZ3/Wm96/hLIclJhIu 71hTAOTuCXTthdyyqwPLQYshtEakRZ2xy7e+MZ1GDM4Yf32Q+2wzqiRvZlEud3//Kyrh XySD7eT5hiaJ05lX14JE6SOB3s5S1sGgRboN1wYwUuo7SB38K2EnEZWkb56LIJyecNhg ssab4dffiIol0eu/qLWw0OgUjRnVR5p7sK9S1V5P8lt3cVv03MPTQNVxDnsZzJVCpfr+ umskxCEAbiPCi3Wcakpj14w2IMpTBlU8mmGz1oAxxHEyTdLt1y7rAAAZs7Mc5lDVo4om N3ig== X-Gm-Message-State: AOAM532EJ4iHoen8JpCPITC36Gdu+Pv1ht4Nf5hRtb7MPI+JzpyYGyjy LEXOe0nBQBCggzlrs9kBPcxdYPYvCba+WhhnFds= X-Google-Smtp-Source: ABdhPJwbrBNSAu3Tr3amWDsFHm7dUw19D7r3Wp6UEAM9M+snVRjIJOi6C8CAoEqsQ8IboSZhCG/19DDBBaacc0PSpkI= X-Received: by 2002:a2e:8047:: with SMTP id p7mr520591ljg.414.1594849118452; Wed, 15 Jul 2020 14:38:38 -0700 (PDT) MIME-Version: 1.0 References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> In-Reply-To: Date: Wed, 15 Jul 2020 18:38:26 -0300 Message-ID: To: Marco Pivetta Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="0000000000002d002105aa81bfca" Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: marcio.web2@gmail.com (Marcio Almada) --0000000000002d002105aa81bfca Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi! Hey Larry, > > wrote: > > > 1) return null, which is a non-type, and thus you need to make the retu= rn > > 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) b= ut > > 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) =3D=3D=3D = (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. > > I've heard a few times that this would reduce type safety. Well, on runtime it really does, the same way when you use null in a wrong manner, but with static analysis tools in place I wouldn't expect a formal proof that it's impossible to analyze that kind of code. Unless we are eval'ing or declaring variables dynamically... I'll try to research a bit on that. What would be the default static analyser used for PHP today? Psalm? Ty, M=C3=A1rcio --0000000000002d002105aa81bfca--