Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122599 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 2AEAD1AD8F6 for ; Sun, 10 Mar 2024 04:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710044339; bh=YwHgJ00lc+Z1piSDuzs7X12rgDOXaB2kSZIBFBiXDQA=; h=From:Date:References:In-Reply-To:Subject:To:From; b=VB6TG8lh4v6jTCA1wZiKJzJs3A5F3/tNeWPtTS0WLvBqOXlKCHmhIBn2wOPb86T8b V0o2J2zslsHSmB9lHt8GaTet36m+WeLSCI4AGOp63remYQ3LHxkJoTVm/Uz2dKDQWN z+VJpjiNfZ54i8qYkgdh09Wdq5jNZOqIr6HhMGrCjbgeRr6oLMV1iM+9L8j9BGPk8j r6lnnw3tWyWFzc0C9eP7OT7EpjPD71HBu3IcY+tcdZ3VsGYar/wfNZRmsheiWB6dzJ 56zL6/01T2/L7+/N9tUDsEVbJgyDRo1esXo3Tltq7lX/6iiKnmoT3WMQcs5kJde3GK ED/hYEuTjpyiA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DAAE8180069 for ; Sun, 10 Mar 2024 04:18:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 10 Mar 2024 04:18:58 +0000 (UTC) Received: from smtpclient.apple (unknown [49.48.216.54]) by mail1.25mail.st (Postfix) with ESMTPSA id 889AD60467 for ; Sun, 10 Mar 2024 04:18:39 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (1.0) Date: Sun, 10 Mar 2024 11:18:26 +0700 Message-ID: References: <1773BB80-D9BD-4A0E-B01B-0A9EF402174D@cschneid.com> In-Reply-To: <1773BB80-D9BD-4A0E-B01B-0A9EF402174D@cschneid.com> Subject: Re: [PHP-DEV] Idea: Implicit inheriting function argument & return type-hint To: php internals X-Mailer: iPhone Mail (21D61) From: php-lists@koalephant.com (Stephen Reay) > On 9 Mar 2024, at 21:27, Christian Schneider wrote= : > =EF=BB=BFAm 09.03.2024 um 08:18 schrieb Marc : >> As the pseudo type `mixed` exists since PHP 8.0, which is already out-of-= date, I have the feeling it would be better to force people to explicitly wr= ite `mixed` to widen the type of an overwritten function and let "no type" i= nherit the argument and return type of the parent. >>=20 >> Example: >>=20 >> class A { >> public function typed(int $var): int { return $var; } >> public function untyped($var) { return $var; } // implicit mixed as no= overwrite >> } >> class B extends A { >> public function typed($var) { return $var; } // implicit int as inheri= ted from overwritten function >> } >=20 > This sounds like a bad idea to me as I cannot look at the function definit= ion in class B and determine what the type of $var is. > On top of that: If the type of $var in A is changed then it would automati= cally also change in B. While this seems convenient it could also break B in= subtle ways as the function suddenly gets different types than expected. >=20 > Regards, > - Chris I guess my discussion with Larry was at least part of what you're referring t= o. The proposal here would introduce the same problem as we discussed on the ot= her RFC: inconsistency with what people are used to elsewhere in the languag= e (eg untyped properties). It also means that existing code would have the complete opposite effect to p= reviously, making it a huge BC break. You'd likely have to have two stages: d= eprecate and then remove use of untyped parameters, and then reintroduce unt= yped to mean "inherited" type, which still suffers from the issues Christian= pointed out. I could get behind the "first half" of that process: making a type required= (ie deprecating type-less parameters/properties) but I doubt there's enough= support for that to pass a vote.=20 Cheers Stephen=20=