Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125225 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 1272E1A00BD for ; Sun, 25 Aug 2024 16:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724603930; bh=pI9Dzaq7RRR3k3npNY3Rv1sOty9FiK5P4LWobtMo8PE=; h=References:In-Reply-To:From:Date:Subject:To:From; b=UTQBvrMN0NsofgmQ99gtngPu15dk5ENlHqymTJFyGMugVeOkXI6zNwDFj13uDIIvz Qt+R1kk4QE+nl96Ox+VTq1yVyJ1FIqBseYAY9YVfOsjTckgJmJj0cg0yK5JMDQT6Un XT1coDH7tIyUmYmvnnGHQl22K0PCeH76agLCkSYZ/6/I5hnn/Mkd0YnDJSkQlEIeSn kELtmCrE16NY556x52Rppl2TN/grH9neXFA9rUWmI9iEb5xO8z5Zx/VSLylNgtqtu3 /5ulqlk1e+4Kf/E1UutJjy9B6qcQ3HzdV/ebBH3QQVEoK1qBx4dmJ0cdDVzZoHHd2q F1sjx9hP+/ODw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 56C0218006F for ; Sun, 25 Aug 2024 16:38:49 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, 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-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.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 16:38:48 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6bf89e59ff8so19475696d6.0 for ; Sun, 25 Aug 2024 09:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724603816; x=1725208616; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pI9Dzaq7RRR3k3npNY3Rv1sOty9FiK5P4LWobtMo8PE=; b=T2vKiJlhvo5K/GsYr5kcE/vS5HuFf84TRLzLOOLkjZsR9uNvcFFRiAhpF/x5gieLyn iLdcGEgRIblGjCNGfi91gtxr35dwAUjDfCuzZDo1uJCmMr0Tne/H/NSMSkbyhRXirhTo w27i/AnsZV464EgSbTf+QOfLk2SSeQPyRnsNgHiynWuWeAtSAEYxOUqLcunaeNkOuNDC hKFz7cFd7VAH6v2y8VvVbeYcT78L47bgn0XWKPbtvQ3UzKfVWV6yu2f+AOqs3IAF/zmg BNz2tNfOoMkeNGBQ7zMMhpdCnN6WXffJGJOSL8oN10ijfKLrt08+lZku0Hsh38eck2Kj a3JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724603816; x=1725208616; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pI9Dzaq7RRR3k3npNY3Rv1sOty9FiK5P4LWobtMo8PE=; b=CwXX518E8h+WeKFbtGW37NSd8Y9vZDjoKe/Q4Rwm/zvryqHzPOsJc1HnKqO4edZn8u RXdd+YKDIHlHABn8AO5ppuVojHrshmHrp43vr5i/fA/j4h0m83ay/ptR/ovt9ViJjii4 JyAhm4GN1U9Nrjzs2PZYwf/FeJEm+6a8nX1K2uf6O/vLKLs8yim0CSIAOobR320o+ybA 1fDvf6Rdvn8J3orqeDJUA5OyEd7WSzZxj3bHl+xo52Y2cGUdWQbxbIm1Ra656CeNgqIl LPVIyW4crP2d2/xuLQpUfTvhmNyfe6Z1eP74MMN6g+7TTMLGTW2qohbgsF58Za6uCUaf gnnA== X-Gm-Message-State: AOJu0YweQ0uVrW73+DQPYwwX0E3N/nz4q9J/rCmtsg8EQmoMGaCj782W zxdGHX00ULQVgmISKvgiRTmRyNYTJLlmaffq45s2SxPLWvbRa9vje4hvsQBmnhuVSehL6ZZGieC w5BfD7SW/Q63fFaC+ZcrbZucD36AGHnsF8hTHXA== X-Google-Smtp-Source: AGHT+IEecaEz5rDggKD/D6QA91gFanp9Htr6j6yqIngUTIBJqD5H3asRdzoQXo8VoKKM8CUqm8l59dhSxzgVU2dcQUw= X-Received: by 2002:a05:6214:3f90:b0:6bf:6f67:2d27 with SMTP id 6a1803df08f44-6c16dc6d435mr107038256d6.27.1724603815652; Sun, 25 Aug 2024 09:36:55 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com> <3e0d031e-256f-47cd-9a2b-dcdc760f5498@scriptfusion.com> In-Reply-To: Date: Sun, 25 Aug 2024 18:36:44 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Default expression To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Rowan On Sun, Aug 25, 2024 at 6:06=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 25/08/2024 16:29, Bilge wrote: > > You can write, `include(1 + 1);`, because `include()` accepts an > > expression. You will get: "Failed opening '2' for inclusion". Should > > we restrict that? No, because that's just how expressions work in any > > context where they're allowed. > > > I think a better comparison might be the "new in initializers" and > "fetch property in const expressions" RFCs, which both forbid uses which > would naturally be allowed by the grammar. The rationale in those cases > was laid out in > https://wiki.php.net/rfc/new_in_initializers#unsupported_positions and > https://wiki.php.net/rfc/fetch_property_in_const_expressions#supporting_a= ll_objects I don't agree with that. Constant expressions in PHP already only support a subset of operations that expressions do. However, default is proposed to be a true expression, i.e. one that compiles to opcodes. Looking at the `expr` nonterminal [1] I can't see any productions that are restricted in the context they can be used in, even though plenty of them are nonsensical (e.g. exit(1) + 2). Furthermore, new in initializers was disallowed in some contexts not because it would be nonsensical, but because it posed technical difficulties. I also believe some of the rules you've laid out would be hard to enforce. > 1) The expression should be reasonably guaranteed to produce the same typ= e as the actual default. Even the simple cases of ??, ?: can easily break this rule. Furthermore, context restriction is easily circumvented. E.g. foo((int) default); // This is not allowed foo((int) match (true) { default =3D> default }); // Let me just do that I'm not sure context restriction is worthwhile, if 1. we can't do it properly anyway and 2. there are no technical reasons to do so. Ilija [1] https://github.com/php/php-src/blob/3f4028d3d9d63e1dae012a9c350141493b3= 0825f/Zend/zend_language_parser.y#L1198