Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125207 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 BFA481A00BD for ; Sun, 25 Aug 2024 10:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724580215; bh=JoaFoRR172NCtcF/ILkBzL/cYoiB/o700WLBZgCZx9U=; h=Date:Subject:To:References:From:In-Reply-To:From; b=F+QHE6pGdP7X3mC4cv74aTL5Uy21mYQ49ME1LgOj+hQ/cz+l64xxOarE7/EJCTK2x 6JejHH3Kuak+uieSmOUfCTWrsX99TDIVfE8MERSGKdZkVjJws8GB9+d6Y3sR6AbJjL CAtHRIfy+I19l7IG2NoiqHYr8+/FyI/xxERnMcHMiYOLGP7NeA9KqN0Yf51BtBmrFo 4r4lLX2B0YMRw183TVo+sMUGpmNp87CyILr9I4h8Y6N6hUCPBA8F8cEtRmEeNxsu+P +8XcepGHekchBrgUK+wz7xS7Rft0lS8N18/zChlGQE7DR5u3iTZ0BdACd7nJ4vVoqq kFUHNqwfklxTQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ACD42180059 for ; Sun, 25 Aug 2024 10:03:34 +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,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,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 mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 25 Aug 2024 10:03:34 +0000 (UTC) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42808071810so29308185e9.1 for ; Sun, 25 Aug 2024 03:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1724580101; x=1725184901; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=CE5NKTHPnFNqfLbdPUzUw5FNtquZGHewm44Bb+3oj7I=; b=CHXLKf4AyEJMKUL1blU44FRQtL6URNUVNjfKEhk0mHbFhXoUGe4TKomDQGGsnCzRTM HK0b85/rIbXwD4t+WyafLZgvMXQoDPSohs5WdUrLPZVEKnSs4lW3FC34e+IT0J8ff/39 6wb/kekcrDWqgjHxKmugrN00JDdypXruC78MZgdR64h+EKzugFPC8M8PeZLzLui1Y5G6 Lpmt+/K6KYuNU8vYEaCizw8JZIZikIieNOsgwsDOjZo+1n680zvYz+cdNax3FZd1es3I BFshfMm1ioC5p4eSeDX52wvZD6R/FLnfC/RJenopPE0dRLPgCRoRFiNgb9b+/kIj1ZS4 n5cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724580101; x=1725184901; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CE5NKTHPnFNqfLbdPUzUw5FNtquZGHewm44Bb+3oj7I=; b=dTAQ9zXunjsXpTLvfG7/e+FoXJSRy58WOhJus3C6al59Rhy5HnjlTwtv4tCeGwni07 qpIWT0wzuKKN85bmGhpkOeyOhhPfr/mwVL9LdPiwXcEP9O3s1mhffWiJoNB/uYA9a9xL 7vH2Y9BVzuzmMdsXGes+WTQXLExvHo1i6EMiXqql/qlwqSznWdwrfQJPZXfhcIbhmVHk Ykz8WDOAhzNOVNK8FKNbrAPUvXFGaIMpeVlItKmD66d/NKRn2/Nd9Thc85jOW2aBuIJq OnhAvou+L6ksM6Y4Y/afV2KTdoPSgGaISc/zkd40lQBHrN021a+Ala5g+YxkxAlPY/Ru hzaA== X-Gm-Message-State: AOJu0YwKhmgv6dpza4aV7iIuqE7HuRTtVxcxzJ4WCmcSwplC7u4XdLOb QhTN6nBot+7u82q3u9Zu3t0IKLD5MlcJbv0s0E80xY6E5POIYfbH/vINtKqsiCzC94368tCAQ6D 6 X-Google-Smtp-Source: AGHT+IHMn3aSKlwrmP9xgSrErvVV1Ckx9YWQKJl6Pvec4DaDc3h/oSOoOZxrIB/ojIGDVOmddqeaXQ== X-Received: by 2002:adf:959a:0:b0:367:9625:bd06 with SMTP id ffacd0b85a97d-373118e3552mr4655194f8f.42.1724580100506; Sun, 25 Aug 2024 03:01:40 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:c4b4:d418:3b87:bff1? ([2a01:4b00:bf09:5101:c4b4:d418:3b87:bff1]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-373081ffb4dsm8330615f8f.74.2024.08.25.03.01.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Aug 2024 03:01:40 -0700 (PDT) Message-ID: <8f1a3e76-f74c-4334-99f5-b094e45a8cb6@scriptfusion.com> Date: Sun, 25 Aug 2024 11:01:38 +0100 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> <66CAFE36.4080102@adviesenzo.nl> Content-Language: en-GB In-Reply-To: <66CAFE36.4080102@adviesenzo.nl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: bilge@scriptfusion.com (Bilge) On 25/08/2024 10:49, Juliette Reinders Folmer wrote: > (resending as I accidentally originally send a private reply instead > of sending the below to the list) > > On 24-8-2024 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 Ilija, Bob and others, it would be truer to >> say it would have been more difficult to fail! Huge thanks to them. >> >> Cheers, >> Bilge >> > > Hi Bilge, Hi :) > I like the idea, but see some potential for issues with ambiguity, > which I don't see mentioned in the RFC as "solved". > > Example 1: > ```php > function foo($paramA, $default = false) {} > foo( default: default ); // <= Will this be handled correctly ? > ``` No, but not because of my RFC, but because $paramA is a required parameter that was not specified. Assuming that was just a typo, the following works as expected: function foo($paramA = 1, $default = false) {     var_dump($default); } foo(default: default); // bool(false) > Example 2: > ```php > callme( >     match($a) { >         10 => $a * 10, >         20 => $a * 20, >         default => $a * default, // <= Based on a test in the PR this > should work. Could you confirm ? >     } > ); > ``` Yes. > Example 3: > ```php > switch($a) { >     case 'foo': >         return callMe($a, default); // I presume this shouldn't be a > problem, but might still be good to have a test for this ? >     default: >         return callMe(10, default); // I presume this shouldn't be a > problem, but might still be good to have a test for this ? > } > ``` Yes. > On that note, might it be an idea to introduce a separate token for > the `default` keyword when used as a default expression in a function > call to reduce ambiguity ? Considering the Bison grammar compiles, I believe there can be no ambiguity. I specifically picked `default` because I think it is the most intuitive keyword to use for this, and it's conveniently already a reserved word. Cheers, Bilge