Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125260 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 30A751A00BD for ; Mon, 26 Aug 2024 10:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724667224; bh=o7JNjBXwsFEH5SWYD5aPaTxuuY647HRrS1ixaTaLu3M=; h=Date:Subject:To:References:From:In-Reply-To:From; b=e9iGynff+zzhl/uBE+/E4FgyYeyECxlVmUyau7+hg0Z7+IlkikZ1pMn0we9byXzrC LCdebThF5AUt6LJ5na8DIGKyLY4YtvcvgDBj5c6Fi5byZmR69iWirJiCRtR058UQOO ECJr02ywjZrDvAdwQFuHX7e3M/1rl4dekFnT9rcfSLDWOOl49NKQdMe4psBpQnnXNt UvDhSAP8WQw7tDaOKioBGyiuylmLzP+TCKm8eOlg/brbF4u0dOeDoV9zoSJTfH9XGL QFZ1Aa3CvwYtt1Ui5ASedQlq/NJ7mi3BLXkQwHOGWzT0MAPEM2l7RHcN0KqwUNEEVQ MM0cdaOYpy8+A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 18F35180069 for ; Mon, 26 Aug 2024 10:13:44 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 26 Aug 2024 10:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1724667109; x=1725271909; i=a.leathley@gmx.net; bh=frB6oT7iCo3xya5LwLTx+MtADbDAGIWbROZ5ScLQjdQ=; h=X-UI-Sender-Class:Content-Type:Message-ID:Date:MIME-Version: Subject:To:References:From:In-Reply-To:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=SFjb7cKDwDkruaTYcB0rYub/XXGYbyo6pahcv2l6sNskZOwnUISOLNszZnWVKNtv yfAaYv4Qq0kdXjmR8uw8ViJ+tmWRt3eeGLbxexYZ4BN+THV3ZuB11nXVP6j7JrwF/ N1vCgE/e8jwDDJ3Hsu9DrlqANpUD4Z9aQXUVObRsETGtMuM0dhacFTUAogLSBM6CE jbxBtUfHJ9XLxwWIJbhRhUJAsQzmQTtsQ+JyiIpMTSYBGbrHWVWC9whCoOJZCs8lY m77V7FTgLHj85tpGr1Ns5L37Qcbj3z9skQKfwHMhdNdpkMbjf/7Zl5rjk7XFeDu7d kyaPSZXNums6LmrLJA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MhU9j-1sEfzy0Ynj-00gVse for ; Mon, 26 Aug 2024 12:11:49 +0200 Content-Type: multipart/alternative; boundary="------------v19mcFx2HQTOCVPQlUYYUWQs" Message-ID: Date: Mon, 26 Aug 2024 12:11:48 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Default expression Content-Language: en-US To: internals@lists.php.net References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> <15301ee5-7964-4f0b-8804-a19f95f43152@gmx.net> In-Reply-To: X-Provags-ID: V03:K1:K7z97aoE4yN8CXGJdM0O6yOw9kWCgflWz5uhH+01QnJlEr9JrwI SfY5gekMqtWJDaGxFp/Nx/DkeaxtBr1s42M/6/Y4+CUzCtIJSRN19w2Mcg/xDv3powH/MY6 7AF2GoXTJ0Les8cHzByeYr+IBPPaA64HpnfGuAJAsm0JoKjrXVWtPqTenFcmOGDY9jqsGGs 9xK9hv0aGdjW5NNlQG9Hg== UI-OutboundReport: notjunk:1;M01:P0:6eqKLRCZLEI=;SNH120nKNUMGfkaHEhOWpNcxpZb WV8zoB+tZb+kyQloh7lnp8sgJRVZesUsysqioykd4Rt/PEsVO0cYvX/a2P0dyKLcM+JE735MF b+zxx/NGCz1FO/z9bUL6f+TIPPtfghXI1pU8/BO4on6J4sD3PjRyHN9dL1TC7ZU+IsyqDY0SQ sjH6vdsKZWt1DPwQVyjZnJC8AWOj18JGuEc6HyrY9xpXS5NoBoYb9TaG8YprDvE6zg/QGkTrw gb/dOcd2zjQ2m5SLZV+LpFOtJbz/j8XQaAh+pZ+42xOsIpErVElJkOjkIde3R3ZncQuw6wy2J uEo9Tuidzhj8aWE85/gm62MhPTSsGDdkqg4zfaEcwZ1fzyIYQ4avd93JhfZbDdEM6ebuR/7d/ qTvhXZMEoM40eGb6ET733Qx4kvjNIe/LG779LDhYSp9/T+j4PeDVELo0XjCBMQXjGlgE2NYky JU7UQzwkpxy1yjCmI/rsp/7qnhFSs0+0HU/XgeB66OS2OfAZO9Tfl18H6WPttJIuKtwi2DOyi zn9K7ArqgTJX7JYC3cxyv4IaeiAkOUwaIGjH/LJufHD4gzdVzRCXIvdxKqXfuAoOxn9+8MNZA KS+qsqDFLc2rs3BTBHAkmxrgXbuGeBcLfGMS2QZLF4h1kJbKdlCDq589M2iVwCUZnCpuqSmYO CsWSySb+SsnAmOPexHg1+Gdzr8X5QnxVuGsPwrRRl2U/QSgiCPrMLs/jZhqFJ2l+9pw/yToHZ 9r+cQLKl4+tbZVwx3/yZbArbXurkagchAazBvQUn7JEKuEPxT8t992yVZgQ5WE8qa+Oafk0u4 EM3BcY21TffJZM/Kd4D+sm3A== From: a.leathley@gmx.net (Andreas Leathley) This is a multi-part message in MIME format. --------------v19mcFx2HQTOCVPQlUYYUWQs Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On 26.08.24 11:26, Bilge wrote: > > Thanks for this question; I find this super interesting because it's > something we haven't thought about yet. I must admit I completely > overlooked that, whilst an interface /can/ require implementers to > specify a default, in the case that they do not, it is still valid for > implementations to selectively elect to provide one. Therefore I can > append to your example the following case (I removed the `string` > return type for now): > > class ZipCompression implements CompressionInterface > { > =C2=A0=C2=A0=C2=A0 public function compress(string $data, int $level) > =C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 var_dump($level); > =C2=A0=C2=A0=C2=A0 } > } > > new GzipCompression()->compress('', default ?? 6); > new ZipCompression()->compress('', default ?? 6); > > In this case, we get the following output: > > int(4) > Fatal error: Uncaught ValueError: Cannot pass default to required > parameter 2 of ZipCompression::compress() > > I would like to fix this if possible, because I think this should be > valid, with emphasis on /if possible/, because it may be prohibitively > complex. Will update later. > That would be a way to fix it, to basically make isset(default) a possible check if there is no default, similar to an undefined variable check. It would also recognize a default value of null as not set in the same way, so one could not differentiate between null and not defined, but that is in line with the language in general. --------------v19mcFx2HQTOCVPQlUYYUWQs Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On 26.08.24 11:26, Bilge wrote:

Thanks for this question; I find this super interesting because it's something we haven't thought about yet. I must admit I completely overlooked that, whilst an interface can require implementers to specify a default, in the case that they do not, it is still valid for implementations to selectively elect to provide one. Therefore I can append to your example the following case (I removed the `string` return type for now):

class ZipCompression implements CompressionInterface
{
=C2=A0=C2=A0=C2=A0 public function compress(string $data, int $lev= el)
=C2=A0=C2=A0=C2=A0 {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 var_dump($level);
=C2=A0=C2=A0=C2=A0 }
}

new GzipCompression()->compress('', default ?? 6);
new ZipCompression()->compress('', default ?? 6);

In this case, we get the following output:

int(4)
Fatal error: Uncaught ValueError: Cannot pass default to required parameter 2 of ZipCompression::compress()

I would like to fix this if possible, because I think this should be valid, with emphasis on if possible, because it may be prohibitively complex. Will update later.

That would be a way to fix it, to basically make isset(default) a possible check if there is no default, similar to an undefined variable check. It would also recognize a default value of null as not set in the same way, so one could not differentiate between null and not defined, but that is in line with the language in general.
--------------v19mcFx2HQTOCVPQlUYYUWQs--