Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113485 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19547 invoked from network); 11 Mar 2021 19:47:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2021 19:47:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 846BC1804D1 for ; Thu, 11 Mar 2021 11:39:39 -0800 (PST) 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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) (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 ; Thu, 11 Mar 2021 11:39:38 -0800 (PST) Received: by mail-vk1-f182.google.com with SMTP id j15so739959vkc.1 for ; Thu, 11 Mar 2021 11:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1zQCpi33ztl8Qc+ouIKsIJ2d/ZBuD+YhjpRieYXShRY=; b=miT7ZeqEvHxnZNtHDBQVEz2dRH0N3S0vwQCcGuEtXdjOOZc8X4KtXr3eVvLe0of9/W MZ3zfTuzOETt6GKnNhgjRbRSotcdJ+gTaWiM8KqJBKrv7a7r8f3VbefIgdOtjSo6cdkV rJlYI38clRUnPYmbuHPYZl2d8cump3rJLPEgRGxc0NaPkRfvut3M1H8mR7TIkooZrw6V QhKwya5wXurMCLKYJsXzvS8CNHhj1lPD3LzrzZBsIrrRmkJh93t8fQjs1XQL+nyFSWjH a+2ONbGh/Y/FpCPHHCX31ezDi7TQemhbCZ4aKuqqG2+QH+D/aH2tfAhvGQSGTZ7A7Bdm 3ZaA== 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:content-transfer-encoding; bh=1zQCpi33ztl8Qc+ouIKsIJ2d/ZBuD+YhjpRieYXShRY=; b=R3FMC+iX1ALCjrxkWtKFo77Fa+/12ghJG1f//I/cmiagjkvfkU5qiAxdjZEfJAGlTz SbXQO978VtEncOwxSGoA67HNTpb4HGTCS5VkAL7fVSk2eqM7O4Cfk3rgHUkHiCkeeoBQ o9wPFmKQwDF1nVuC7nnmwal0M0fspdqWLfshbcXGMg1ryQp3UhcK515afPkwKk19pcFV qM3b+eEZcQqv2l5v9jz3gwweeKIxCaRDly8gVJinjCM74O4jb9vXjeJ8RTKVLWkaHVhk mBQw7dmVWmALlAveB7WfahOklkQ65EGoXyYZptZ05pn0jloajDGjTuUGb3oRFlBcuLSt 9Syw== X-Gm-Message-State: AOAM530+JMOVFcVW8aCX4k8KChQLdDxfd2JFF8RM1IsmdTQr1KNJJHTZ CIeIHcHIj/OVjcc1QAx2hQf/iCSDczeuUSm0HjH7Ww== X-Google-Smtp-Source: ABdhPJyAsCSd+vIpBwb7pnynW91o61Ey6SMOA7CpEvevdsLji8uzspxoumjgs3t5aNr12ezlKgz+6DwGWqCZiAej++4= X-Received: by 2002:a1f:df06:: with SMTP id w6mr6574261vkg.18.1615491577265; Thu, 11 Mar 2021 11:39:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 11 Mar 2021 19:39:26 +0000 Message-ID: To: Matthew Brown Cc: Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] noreturn type From: Danack@basereality.com (Dan Ackroyd) Hi Matt & Ond=C5=99ej, One of the things that makes PHP different from other languages (and for better for a change) is that every function returns a value, even where there is no explicit return statement. This eliminates a large number of edge-cases in code like: function log_result(mixed $bar) {...} log_result($anyCallable()); is always valid in PHP, whereas in other languages similar code can either refuse to compile, or error out when run, or other things like 'undefined' variables. I.E. in other languages, there are three exit conditions: * no value returned * a value returned * function has no normal exit And so other languages need to indicate between 'void' and 'no return' But in PHP there are only two exit conditions*: * a value returned * function has no normal exit I (and others) brought this up during the void RFC: https://news-web.php.net/php.internals/88990 and said that null was the right choice over void, as it matches what the language actually does. That would have left void available to mean 'this function' does not exit normally. Unfortunately people in the community have started doing what I feared, and using void as 'no value is returned', which is not what the language actually _does_. I realise the above might be slightly discombobulating if, for example, some people had written large static code analyzers that had misinterpreted void like this. I think we should introduce null. But we shouldn't introduce 'noreturn' even if a large number have misunderstood what the behaviour of the language is. It might be appropriate for the other languages that are listed in the other language section, but it's not appropriate in PHP which is different to those languages. cheers Dan Ack * so the usage of null and void return types should be: function returns(): null { if (rand(0, 100) =3D=3D=3D 0) { throw new \Exception('Surprise!');} // intentionally no code } function never_returns(): void { if (rand(0, 100) =3D=3D=3D 0) { throw new \Exception('Surprise!');} while (1) {} } For both of them, there are exceptions to the declared return type, but otherwise 'returns' returns the value null, and 'never_returns' never returns a value.