Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124757 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 7279F1ADD5C for ; Mon, 5 Aug 2024 11:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1722856003; bh=MCPjJXWJ0Lm60Rdfv4Qgyx3AQLisAMfjAoHSsCcHcGk=; h=References:In-Reply-To:From:Date:Subject:To:From; b=IdhfKS7YNGU9fagSOJaKYweOLtOhoBF24gs7CuT810RfLjmuTdEDAZZffYM5vNjQd pdLwgrqir9YMWhckj52B6PjT8xAO55yjkMYGzB0VTg8JgombkTkCv1TSJc7/IN2bRi ljFaJ4CJ0RIgCm0CJrVweUDZTR1WYW+aSEnIdQU5NDY032ZmBWIUqiuuHCWuQO3fHO jqJb++P0HUqpEELd8ySvhLmToI//Uy3Cchin6Z8rEu4jYTr7PtEhC60LfksgR0a6Jq z4A/eAIyX9QPOZmhl/bwUxDrzM35yHA0yFZ4XSayK5d0pW38rGZskeaUDN1qaJZ9SB VMPrgG/2U6Jpw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B731D1801E3 for ; Mon, 5 Aug 2024 11:06:40 +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-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (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, 5 Aug 2024 11:06:38 +0000 (UTC) Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6b5f46191b5so56542116d6.3 for ; Mon, 05 Aug 2024 04:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722855897; x=1723460697; 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=MCPjJXWJ0Lm60Rdfv4Qgyx3AQLisAMfjAoHSsCcHcGk=; b=R4m3Zp4vEalu1vndmqdsLY4Y6Ia8v1IA3Bac2MtPMyGeH7zKjAK8pnwYrsgIydLW9G ppqRP7MZF+ZUSgz6DktUklUvh1z2FyplB9D6W2M589ymFcNVOIlOTSvkac5suu7g8aRu an+AZg0rqvdWsyVItl7oEbGApI0bt3LL999kctaZ6ioGVHnGIssp7xJwYlZDv9r+f+t7 DwY9C2zHvSUx/BE++Sb+3rrBQXgwkHgHd8iVNWVYImZprmlwLYO7Wjcgj0ey+qgADPSi N4G5X8jvPvP78ues3nB0nlezJ5sLd4xcw3PQN6H67RsQHlvAQ8RCbCsgtec1a8DeWOVr q9lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722855897; x=1723460697; 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=MCPjJXWJ0Lm60Rdfv4Qgyx3AQLisAMfjAoHSsCcHcGk=; b=Qcl4AV5qvpIhpqOyT+cpmAqQNR4L8H/LZf+lpXzq7U4niSdgtQxDvzcc8PVUmEjznF WtRrzXYQ1ibmRVLBgZUEI1hbEDMrVwcFgRpVEMWzrEL4Y9OfvL3T3c0Jd09rMWfMKDGR kxm4aTh4siRjBIYTPfTeQrwT6iGBA2ULkvGgf1RCSi6kJ1b+yqXMBYgA9rnW12Xlyri5 zibD3x6VlC2OzlxChtdPaAjEX2MsZudpwjZ+0kFLVbOu2AwMTrthuuCDoFUUSX52Ctde yl1wtxjqf+ASfbZpEK8nsJcgV83m311euTgJEzGvB448BVJhPcfY/bQrbWMDLAPgyV5f gYvA== X-Gm-Message-State: AOJu0YzdqfrzuAQzAOLhhDufWL0KJZnWvKHJOzM5xvFgNc+8OxOTMlJw 2HqOy6n+oPnchND7tewESZ3mv8QRkErIXCiQU2mNQhRQhdDcqGy+ENgTFHojcrrAkI4v3p0Bxmo Xme/PtSelDe+HAaT9sER/13uvHEvlmXewDo/v5Q== X-Google-Smtp-Source: AGHT+IFYg3Nl804JwzCxxCEW8gDTWODLy+DL2ojPXq8usHyaTQCCRjRENbpWIzMcPrmVcUlo/q62jq9uL/+ce/7JgPc= X-Received: by 2002:a05:6214:3105:b0:6b0:9479:cdc9 with SMTP id 6a1803df08f44-6bb984467d2mr101515216d6.49.1722855896613; Mon, 05 Aug 2024 04:04:56 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1a88918e-e808-d778-45e1-53797660e093@php.net> <3563cf9b-8eab-4c82-b525-a5d2f9a767bb@varteg.nz> <38920A4B-790D-48C7-B2F6-C49D3F506232@rwec.co.uk> <0824789d-0e36-4628-85c1-4b8d9b7f86af@varteg.nz> <2244a37f-8c51-448d-8a56-329ff32e6470@bastelstu.be> <0e1a21ddef3c7da17a3539b92d5f442763f4b1f8.camel@ageofdream.com> <5f1da5195e2aea7ec41e95ff4354f50b1717d3cf.camel@ageofdream.com> <599a445530357d080cb59c9443cacd5cfd5da82f.camel@ageofdream.com> In-Reply-To: <599a445530357d080cb59c9443cacd5cfd5da82f.camel@ageofdream.com> Date: Mon, 5 Aug 2024 13:04:45 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Add Directive to Make All Namespaced Function Calls Global To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) On Mon, Aug 5, 2024 at 10:22=E2=80=AFAM Nick Lockheart wrote: > > > Sorry, my language was not precise enough. Your proposal suggests > > making unqualified calls global when the directive is present, > > whereas my proposal suggests keeping local scope as a fallback, hence > > the two not being compatible. > > Keeping local scope as a fallback would still require an NS lookup > opcode. In the general sense: Yes, we would need to keep the NS lookup opcode. However, functions that are known to exist in global scope would not compile to it. The same goes for your solution, as code that doesn't opt-into disambiguated lookups will still require the ZEND_INIT_NS_FCALL_BY_NAME opcode. > My proposal is that there still be an NS lookup as the default > behavior, but allow an optional override. > > That is, users would have three options: > > (1) resolve all unqualified function names to global (no NS lookup) > (2) resolve all unqualified function names to local (no NS lookup) > (3) Use the default behavior, which at present, is local first, then > global, with a namespace lookup. (no change to user code, keeps BC) > > Your proposal reverses the order of the default NS lookup from local > first to global first. > > That's not mutually exclusive. Sure. But it's questionable whether the motivation of introducing one when the other already exists is still there. > If my proposal *and* yours were *both* accepted, users would have these > options: > > (1) resolve all unqualified function names to global (no NS lookup) > (2) resolve all unqualified function names to local (no NS lookup) > (3) Use the default behavior, which would now be global first, then > local, with a namespace lookup. (no change to user code, keeps BC > working, but changes the default automatic lookup order) > > I believe that my propsal also helps yours be more viable, too. Because > if your proposal was accepted alone, and the NS lookup order changed, > then it would no longer be possible to do unit testing with stubs that > replace built-in functions, UNLESS there was also an option for > developers to instruct the compiler to use local functions over global > ones. I'm not sure your proposal solves the mocking problem. If the engine is to interpret all non-fq calls as global or local, how would a library include your file while switching this configuration, when it is implemented as some directive in the file? Also, how would only singular functions be mocked when there is no fallback to the global scope for the rest of the functions used within the file? That would necessitate mocking all functions, even the unmodified ones. > > What I'm saying is that: > > > > 1. If the vote fails, it might have been because some people don't > > want opt-in behavior. Niels just voiced this opinion. > > Every token added to a PHP file is opt-in behavior that changes how the > parser works. I don't understand what you mean. What Niels was suggesting is that adding more context dependency is undesired. I.e. language semantics should not be dependent on configuration. > I think something needs to be at least as formal as an RFC or people > won't take it seriously enough to contribute feedback. > > I'm trying to start a discussion on this and get some momentum so that > we can hopefully implement something in a near future version. Fair enough. But it should be made clearer what is being voted on. From reading the RFC, it is not clear that there even are alternative options, which ones have been proposed before, what points have been raised in the discussion, etc. Ilija