Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114053 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5733 invoked from network); 14 Apr 2021 13:45:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Apr 2021 13:45:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0675C1804E2 for ; Wed, 14 Apr 2021 06:46:50 -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.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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, 14 Apr 2021 06:46:49 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 4FCD15101324 for ; Wed, 14 Apr 2021 13:46:47 +0000 (UTC) To: internals@lists.php.net References: Message-ID: <918bd585-0a5a-063d-7d4e-c89eadef0dde@processus.org> Date: Wed, 14 Apr 2021 15:46:46 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] [RFC] [Discussion] Adding return types to internal methods From: pierre-php@processus.org (Pierre) Le 14/04/2021 à 15:30, Nikita Popov a écrit : > 1. The one addressed by the RFC is addition of a return type (or more > generally, restriction of a return type). This is generally done when the > method was already guaranteed to return that type, and this fact was not > explicitly declared previously. Direct users of the API are not affected by > the change. Overriding methods can be affected in two ways: They made use > of the lose API contract and returned a different type, in which case the > implementation needs to be changed. Or, and this is almost always the case, > they already adhere to the stricter API contract, but now need to > explicitly declare this fact. > > 2. The second one not addressed here is the addition of optional > parameters. Take for example the recent change of mysqli::execute() to > mysqli::execute(?array $params = null). Once again, direct users of the API > are not affected by the change. Overriding methods are affected because > they need to pass through the new parameter. As this is an addition of a > new optional feature, not passing through the optional parameter only > becomes a problem if the new optional feature is actually used. Whether not > passing it is "harmless" depends on whether the API declarer and the API > user are the same. Hello, Having type-inference wouldn't transparently fix some of these issues ? Let's consider a method such as foo($array) which returns a bool or a string, for example. And suddenly, the types get specified as foo(?array $array): bool|string. With type inference, an implementer which has correctly implemented an override this signature would inherit from types if non-specified, and wouldn't have anything to fix ? This is just a stupid idea, but I'd love that, not having to repeat all types when implementing method interfaces or overriding methods, and just trust the compiler and or engine runtime for inferring types when checking it, and do it in a smart and robust way so that invalid code cannot compile or run, but valid code be easier and quicker to read. But sorry for the noise, I'm deviating from the original issue. Cheers,