Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125271 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 D99921A00BD for ; Mon, 26 Aug 2024 13:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724678401; bh=Xj47Jg0ZNEODqV6hVJp+K0gZpVqUCqvpcJKpsbSBNzI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=dECpAw+8wFW23EJ4LMpU8tk0zcxHRWtcj5VT5KZbB0DWwQk3FKdNEgjtmDqkbjQVt TgDuE/fYBFhE9zjs+cBEV3RliozV8cynGOMCoGSxZGpT3hbqWAYpMK1mkCIAXUgHAN 9XX+v+NyPdnaQhF6gu6+gMFywrWZT4RY8fvFicI1I8eBfGKWjO4JOHvx6fbGwqMXHJ i/6L4TG0c96aevbpbA4SWWxkG9Tty5Lht1h+rU9rwWNaLYGQBZP+0U0jdxeGDEduqW 7hKGgWiuTFjRzE/2ZbpxqfqPSRPthE3vXwLMWRV7QD16mbz38CPIQl+UU+2NHuTKH6 BdUeXrE3tyGUA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6774E18006D for ; Mon, 26 Aug 2024 13:20:00 +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,HTML_MESSAGE,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-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 ; Mon, 26 Aug 2024 13:20:00 +0000 (UTC) Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-428178fc07eso35589285e9.3 for ; Mon, 26 Aug 2024 06:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1724678286; x=1725283086; darn=lists.php.net; h=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=m+osISEsjT+PoYmdyy+Xy3hH7ewYndcADTTKTksc0uQ=; b=xnfCGB6IJt1w6cCyjnhFvBfbPlNplRxrfFR85nE5XvhV+kCcqaRQfmEGYKGCpubrr0 K5v7sv7lWYJqDi73t6c8LEgMq2J1fjIz9U+CezbCv2CClDZd7plMsW6VPkdbuQOgsevR E1gle8K6wYxFlC7KBvigtsow3B7nxE9lzxuA38GVzVdtpqT//oVseLnD+0qnpDdL8F2+ 21ocU6mpDXxri5+gD3RGybj2y0S4ohGzHMSUolH0M54oPirWjx83D5ZAtFxZ4R1Z93xE kjAfOviGVBD/yPWPPcUECNKV3yn9hma1u9LzpWCSNIaru4pgbAT5hdEVkbH2rmhw5Wgr rPmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724678286; x=1725283086; h=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=m+osISEsjT+PoYmdyy+Xy3hH7ewYndcADTTKTksc0uQ=; b=wMFFki6KQyZ/K7/CpvnBtaQA3FZ3blZCckrMRspoCJ1pVY0aDwDpd/ZM3OwIm+X8KD 4BCFBj8R7xZNhR7/VEv+Ng5NU//jMUPCQ0g94SgfagLzcBrv8KCPWf7VTxDTRL2lRex/ FxIJEFkCWLOv8qtwDHEtHs+O9DCxMg/ZdtoXMOD4PqXbfMMc8Vf72q3LL6jvMwcIWtGW 37yXd2I9dexepLEAMWloD8ty1LslX0weXtGgif9gEHvGQc/TIZ/CfOBhl+SUaNSCKpRS 3onY04Y/hj5vS/9tO003pdZewaW9KKDCpxlWthN+Kh1yZzrG85Daujgi7xtxltFQKeVT Lqqw== X-Forwarded-Encrypted: i=1; AJvYcCV7ofo8mpty92WnFYmBhd40GnQ1SaaA90Vj/CdjD9Ea1/CVW6EQ+fApKpSHJnl+NBus/GakLOXSjhY=@lists.php.net X-Gm-Message-State: AOJu0YyGDE+64bUttTP4ceNvB1174ECYEpVEaWzgzGCIdWqRUmN7/tsJ wg7kx6fAuk0uPEEePzQj8BDMOMQxYy+5vhaoogQvY4sncgac3uDsLVlTeJeRiDHJqTigoIH4s0d 5xbE= X-Google-Smtp-Source: AGHT+IGFryqNlLP6rTnH5iGAmNbfxGSbVy3DttS4k4/xsjJG+gILlPFAVKPGvPCcqvOHBxvkb/WcWw== X-Received: by 2002:a05:600c:1e13:b0:426:5c9b:dee6 with SMTP id 5b1f17b1804b1-42b8ad556a8mr48987495e9.26.1724678285681; Mon, 26 Aug 2024 06:18:05 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:24c4:e0bf:99bf:8460? ([2a01:4b00:bf09:5101:24c4:e0bf:99bf:8460]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-42ab87e881csm209402865e9.1.2024.08.26.06.18.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Aug 2024 06:18:05 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------W8KALf744QErZkzoPcgln1OI" Message-ID: <182eae62-2808-4caa-918a-76066e4a0f39@scriptfusion.com> Date: Mon, 26 Aug 2024 14:18:04 +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: Jordi Boggiano , "internals@lists.php.net" References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> <4086414f-f8cb-4209-a127-0de19f065a47@seld.be> Content-Language: en-GB In-Reply-To: <4086414f-f8cb-4209-a127-0de19f065a47@seld.be> From: bilge@scriptfusion.com (Bilge) This is a multi-part message in MIME format. --------------W8KALf744QErZkzoPcgln1OI Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 26/08/2024 12:55, Jordi Boggiano wrote: > Hey Bilge, Hi :) > > On 24.08.2024 18:49, Bilge wrote: >> 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. > > Great work overall, I'm all for it and even though it's not something > I saw myself using a whole lot, the json_encode example sold me on it > being more useful than I initially thought. Thanks! I concede, this is one of those tools for your toolbox that you will seldom reach for, but comes in very handy whenever you do. > > One question (sorry if someone already asked, I scanned the thread but > it is getting long..): I don't blame you. I'll summarise the main takeaways in the RFC later. > > Taking this example from the RFC: > >     function g($p = null) { >         f($p ?? default); >     } > > Could you go one step further and use default by default but still > allow null to be passed in? > >     function g($p = default) { >         f($p); >     } > No. The RFC has a very specific and singular focus in this regard: to permit `default` /only/ in function call contexts. That is, although `default` is a valid expression, it cannot be passed around or stored in a variable. Since this is a function definition, rather than a call, this will result in a compiler error. The specific error we get in this case is: "Fatal error: Constant expression contains invalid operations". Cheers, Bilge --------------W8KALf744QErZkzoPcgln1OI Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 26/08/2024 12:55, Jordi Boggiano wrote:
Hey Bilge,
Hi :)

On 24.08.2024 18:49, Bilge wrote:
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.

Great work overall, I'm all for it and even though it's not something I saw myself using a whole lot, the json_encode example sold me on it being more useful than I initially thought.
Thanks! I concede, this is one of those tools for your toolbox that you will seldom reach for, but comes in very handy whenever you do.

One question (sorry if someone already asked, I scanned the thread but it is getting long..):
I don't blame you. I'll summarise the main takeaways in the RFC later.

Taking this example from the RFC:

    function g($p = null) {
        f($p ?? default);
    }

Could you go one step further and use default by default but still allow null to be passed in?

    function g($p = default) {
        f($p);
    }

No. The RFC has a very specific and singular focus in this regard: to permit `default` only in function call contexts. That is, although `default` is a valid expression, it cannot be passed around or stored in a variable. Since this is a function definition, rather than a call, this will result in a compiler error. The specific error we get in this case is: "Fatal error: Constant expression contains invalid operations".

Cheers,
Bilge

--------------W8KALf744QErZkzoPcgln1OI--