Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113458 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32356 invoked from network); 11 Mar 2021 03:45:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2021 03:45:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F1EBC1804B8 for ; Wed, 10 Mar 2021 19:38:01 -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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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, 10 Mar 2021 19:38:01 -0800 (PST) Received: by mail-wm1-f54.google.com with SMTP id r15-20020a05600c35cfb029010e639ca09eso12323294wmq.1 for ; Wed, 10 Mar 2021 19:38:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding:thread-index:content-language; bh=e+fHMUbwnKcFbEF8X32AhiIp4kG6mG7HNBkeRfrshLI=; b=bLrqpqXpwuJChbsu53UPem9fC6Cv3rZKCKfNrb3OhwIWimC1ITezf5m+pGgAP7r+zh C2NwDAM8YYaXThoMb0KqjO4I6LLoefujEV4b4GE97yROjMNH5AuDXNqN7hFaQTOMxlEs PmM5cJGtPneYWkhNhx0oLIfb483byWHymTlPHReN7KruVX2fqRKpjNQVLyP0QLnuO9lq F5iPekRuipf8jXI/B10dI1XsAv/tjMAKO3RTQZ5vL6DuDZVuI0pxP81cukmlbvpxPvAM tINrVYJO+wSA+Ls4t2+FXdYCsyZdkhhUhZFTjRDjQyEXH3DQOE/WXAoVYHEnakaiQk1Z nRUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding:thread-index:content-language; bh=e+fHMUbwnKcFbEF8X32AhiIp4kG6mG7HNBkeRfrshLI=; b=mKlQojuGYAQw/JsA/BETUf6fzedpxTLwO1eAl68haGJ1RXObV8X/UIrW3Qs1vUiJeX 8H1KAVWUndl42Y7VqF7P+0PEkH81ri30WiBpgNVq4vutjFC2/YT2fET5PJi4emzJZftj CG03fcAsv079weWzeQmo+6NEJqlo043MtRrek8qgW+rM+LVr7NA7VU3SpclJFjl4yJKv 2Ex6GzZHu4xcqUuQTCCHhTivRdxQL8T4RmjPMUSJJmorIVXRZstaCf2IW+rzxGSkxNNH dog7DCoLdnCji+FZ7SnVWU+Ajv97vhCYsSO3lXsOJMy1Hoa798DksHVdyqqQamJ+mNX2 4MAQ== X-Gm-Message-State: AOAM533biq5XdpUnl3QxPNi1PkLBA5DQ2NjVFoOdD9WBPbHdT5Fpe8nw gNB/7PrJ1m3lybL80MRp0cNHlV2mfMAZxA== X-Google-Smtp-Source: ABdhPJx6o4GGOnwVnzdQo9WprhQgSdMXcY578CDwNfdNuJ0YPfmLpWaoFP9Bhi+4JXQNIlVOuCcnTw== X-Received: by 2002:a1c:1f8f:: with SMTP id f137mr6090663wmf.66.1615433878946; Wed, 10 Mar 2021 19:37:58 -0800 (PST) Received: from DESKTOPQD1QNOQ (static-12-12-248-43.dnt.net.pk. [43.248.12.12]) by smtp.gmail.com with ESMTPSA id d7sm1513062wrs.42.2021.03.10.19.37.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Mar 2021 19:37:57 -0800 (PST) To: Date: Thu, 11 Mar 2021 08:37:52 +0500 Message-ID: <01fa01d71627$edb078a0$c91169e0$@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdcWIWhUVGiKtIFlT2S6aYGhnBfsCA== Content-Language: en-us Subject: Honour the Default Value of 'return' Statement According to the Function Signature From: office.hamzaahmad@gmail.com Hello Internals, I congratulate you for the successful release of PHP 8.0.3. I also appreciate your efforts to bring union types and return type hints. Although the type hints have made debugging more easier, it has created another problem for those that use 'return' to end the execution of a function or method call. There are mainly two usages of 'return'. First ends the execution of the remaining statements. Second returns a value. The return type hints aids with the second usage and ignores the former facility. In other words, if one wants to avoid large code blocks i.e. the conditional blocks, it can write like following. The above function returns null if conditions are met. Otherwise, it returns no value. It was okay when there was no concept of return type hints. When return types have been introduced, the behaviour needs to be evolved, too. What if the return type was set 'int|float' in the above example? The compiler would give following error: Fatal error: A function with return type must return a value.... Similarly, a function with ': void' signature produceed that a function may not return a value. To resolve such a problem, I request to honour the function signature when you evaluate return statements. Instead of looking for no 'return' statements in ': void' functions, verify whether a function specifies a return value. If the function returns a type other than the types declared in the signature, it may produce wrong type error. If a function with void returns a value i.e. contains a non-empty return (return;) statement, the compiler may throw an error stating that a function with void signature must not return a value. Likewise, 'return' may return an empty array if the return type was set to array; the similar case applies to string, int, float, object etcetera. In the case of ': void' signature, 'return' only ends the execution and returns no value. PHP also allows to specify only returning 'false' from a function call. What if you extend this functionality and allow specifying literals including null? If nulls are also allowed, the backword behaviour could be impleamented. For example: public function foo() : string| null; Consider the following example for literals. I am positive that you will consider my request and provide me with the feedback in case of any inconsistency in my argument. I wish you best of luck for the on-going work for the PHP 8.1. Best Regards Hamza Ahmad