Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125257 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 A6CCF1A00BD for ; Mon, 26 Aug 2024 09:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724663152; bh=CuqIGfc/oe14QGXM0kXd9Qr7UBw99li/2nS/w9ayd0g=; h=Date:Subject:To:References:From:In-Reply-To:From; b=GrWNbw85TzIsG1MJBuTz7DiePx4IN+ga6Iee/5J0zXjDXMpbVlutTgW7TLnTKF7Az VfuNkK9Co4r8L9DCNWPUrOXPxV+duFv6xErWeTphHt8AIYw1agG4vouzZvnI5TkaF0 PMUdDToFN2k5zcICc0eJ5TeeANJV7wB+zSTczfgMf0OZPMdILuICqiNMRyfrjaaDaX dK1lb9E+tiSS2YYuF+iXD4+OwGDxN0q6CmTBXybyPWRWaW58pNsKIIbTbbwAkgw5Et Z7P5KKhNRpT7VU/Kc3dIVAO+1CPtvTjzqgKKQrR0+8sya9Ee9xDVOIWUdWo8lQjGmf qDcmyFyb6e/Zw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E73DD180042 for ; Mon, 26 Aug 2024 09:05:50 +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, 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 09:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1724663033; x=1725267833; i=a.leathley@gmx.net; bh=CuqIGfc/oe14QGXM0kXd9Qr7UBw99li/2nS/w9ayd0g=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=F7eMZoaRtxdBdQX51vqm3qAGPzhhjFOsIRoOc0L4oflatFOyy9ltc4AUlIcDPjn3 pF4nBzJrpxWORUbquQvqzp/KuEmTk+9U23KXksKd9FUOG8J9NHRppUx44fhgCNuvC tyorhfLx3yzk7V/jKLJ1q/FLw0R7VPGerx6Op9rCorZZtcLIf+xgztWXcG2QAWQt1 6ygZRdCoa6mnWrdpbKcJYj1+joH9dTADPK4a/Owu/+bT7P1GrUNixbixKZvztwndC 7gWfcssIb2Dc59IWLDHkeuAm0UAASWKA0Po2CsGjqWjFiQkNZWxPn+9MevrnrWEW6 EqenT1HI/cCo6IJmZQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1McpNy-1sA06N0LsQ-00hs2d for ; Mon, 26 Aug 2024 11:03:53 +0200 Message-ID: <15301ee5-7964-4f0b-8804-a19f95f43152@gmx.net> Date: Mon, 26 Aug 2024 11:03:52 +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 To: internals@lists.php.net References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> Content-Language: en-US In-Reply-To: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:8kjhm/gw1emKTe+XJ/tAGeU3iy6SPOAWukIMUQ0cpSKF9d1N7E9 IRggZ/8DEiy7bxEH+v1m8jYf2wFuKIZh8Wa+r5/1AuNVJ6Ia9Oa+pSPXUMS7hPlIgY6h6/o OCZgwLKcLd6WqcDIvkE7OtqUQs+VXCJOnoZRnBStR0FctYfTNdA64dYAoeoTlCjzT70lb9l RzxvS4sIEzO3cAAu6MxWQ== UI-OutboundReport: notjunk:1;M01:P0:jc5GRpOsYZM=;Jb+2GGSXd4gKmrjpzqhuPD5iiaV 6cSCiqpTlUEEIg6zoVemZkEbt33kl5+NUI0s+Ye6k0/G/gM1xLrHSdxurS25CShnckntQtuKd 1l943ptcu340jGjHKod397FJdA/wFOylUUwYO9pEWHEj6N+kIfxxAOV7Aky8uzUC4PnE7+YTO WYL+p1hJDlJGfWqhgN6l4NT9lMh7h9PbBAHCYvv9KlDu0KmR9n6xTseTT1OBNDG15XLT0Ijyt v5lm5y+QPoH5DL9pnq1MchZe8LrdP76dWJ2ITc/wgLIn+Lg7x23bXWdIhvCpLjH7rQEm7llYF QuK7P1NwgoWJQsfykq+Ezf5DFIV4Eu7KQRXQzccVXQkzUkOoauroQFDSGDnQ9XWvQ7K/q/xL5 A/AHYHZl6xYe0Ke98f17zT7/WU7Zj1vw6JDwt8Xx4l81/gNJsd6tDxTiY0cyTxFpZIQKj7KNR 70GtALCf4Xf6WMR1AjnVEXXbI/DgqFdbob7uBiFb5NH4WQjpPk9lcTRLsE6Kl8MNlx7fNGBgw pw22JK+gGzb0Nfpna7eLbLmmYTBD3YxXuJOyFMzRILHX/WdaTWRrjHSLgB77Jg92T8isPF3Y7 Ohco3TLrLLlO18q4n+Yu/29fBMh5dJSbIBlya2XISgAkxiLw9ss/XbfbcWJi3o7lBDMlk72gz M761S6mRx0H2R7QvxpImFL0MOxAQhbuI1M62XvmHZWzBLwAJj9GqXG8Qa0dXmSCD+kn15qF6l 4ouWnTLNxRmBtPTuHQziXjLt2rkPWkcZiuyDxnk/hqconfiKgx8ikOtT3uUXVP7tC8jnBJgIB 5oWN2KlX7VFkevGbTTPZq18A== From: a.leathley@gmx.net (Andreas Leathley) On 24.08.24 18:49, Bilge wrote: > Hi gang, > > New RFC just dropped: https://wiki.php.net/rfc/default_expression. I > think some of you might enjoy this one. Hit me with any feedback. > > This one already comes complete with working implementation that I've > been cooking for a little while. Considering I don't know C or PHP > internals, one might think implementing this feature would be > prohibitively difficult, but considering the amount of help and > guidance I received from=C2=A0Ilija, Bob and others, it would be truer t= o > say it would have been more difficult to fail! Huge thanks to them. > > Cheers, > Bilge Hello Paul, I think this is an interesting addition to the language. Personally, I would replace the full expression list at the end of the RFC with more examples in real-world scenarios for most of these cases. As far as I skimmed the discussion, there is some worry of "wrong use" (which I do not necessarily share). Showing more examples could be useful to focus on how having default being a full expression gives interesting use cases, instead of talking about what (in isolation) nonsensical code people might write. For me there is another question. When using interfaces and classes, default values can be introduced, like this: interface CompressionInterface { =C2=A0=C2=A0=C2=A0 public function compress(string $data, int $level): st= ring; } class GzipCompression implements CompressionInterface { =C2=A0=C2=A0=C2=A0 public function compress(string $data, int $level =3D = 4): string =C2=A0=C2=A0=C2=A0 { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // do something =C2=A0=C2=A0=C2=A0 } } When I have the GzipCompression class, I would know there is a default value for $level, but when using the interface there might or might not be a default value, depending on the implementation. As far as I read the RFC, using "default" when there is no default would lead to a runtime exception, but there is no way of finding out if there is a default if you do not already know. Being able to test that could be useful, although I am not sure about the syntax for that. In the example when getting CompressionInterface, I might test for the existence of a default value of $level and leave it at the default if there is a default (maybe I know that some implementations have a default value, others don't). One could test the specific implementation with instanceof checks, but the advantage of "default" could be that you do not need to know the implementation and could only adapt to possibly defined default values.