Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124784 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 BDE4C1A00B7 for ; Mon, 5 Aug 2024 18:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1722883870; bh=y8FJvXDHPkArDIJzl0oBUbiTsEibq2k4sh0AJpSpylA=; h=References:In-Reply-To:From:Date:Subject:To:From; b=bp7u17QslSyqnvcI4uaKMwXeQS00gCu7dqnALDTHWV3jCJ0xwLmyZadMtJt9+77eM frEDyFHOMwxjOAaI3bNyr0HX2UBPXn2Q6unbLT0qTp4ZbTBWuwXUBpiQ7yerRW5oQu EoaTgcgguGc//8GM6p44jlV1GIFQqUM/OvViQQfdIbjrqIp8NDa5OAHXuc9QVJNo9K VYYRjio9vGEfIy78EzQMX5rUnSA6/hnTfzlsF/VGhHjMLOfDBG2TFxDy+PqXGODT3f 14Bg80+htiHZtN+g4kEqXserd8amf423hgP6KmxpzAcx+jSgnw+5xKZ1Ehgom+jHdk eWEaalxm3/gUQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CFDE518006D for ; Mon, 5 Aug 2024 18:51:09 +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-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 18:51:09 +0000 (UTC) Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6b796667348so573156d6.0 for ; Mon, 05 Aug 2024 11:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722883767; x=1723488567; 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=y8FJvXDHPkArDIJzl0oBUbiTsEibq2k4sh0AJpSpylA=; b=aryHh82vCW5X+ZDSs8mC4nLMG/XkTO+8o7VMuiia1eQDXhxRVn0PUR9GMgzbiLaDev Nf15v2s643JpYJhETlRox3Ok2BnEPsTv7iLcAHQYb5HPIISLbZZqZ5tDTk0F4eo1nS0Y yOlmw2hWJ3FY9hJd/Nh6u9SPZTHV4bIbSGfdSWqINBsL+UlbTlXGfRDHFHarF8+ISVkO zmcCLGIt1Xik4Fil7LdHR+vS7CTohcujBDrObV/pU5CXL3bYakgxeDnXyIPmfjIfX1z2 OjZMqINgvXx0lMbaWZlM/Egp6+uOdYUyZKnnU2GsHC5g9iwl5obtcqNRhRE2DZy0rRqo Fzsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722883767; x=1723488567; 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=y8FJvXDHPkArDIJzl0oBUbiTsEibq2k4sh0AJpSpylA=; b=eqWpa+4XD8MWeF/z8LPXCMP+gvVFl7N/lsErReXBxUnSgsgTK6gkZhKH72ASnHsppx HjxhvOd/9Z2pSefrFmoK0QBjQxSv5q8tJDDTD/A2oo53FH5pI7Wrj6g0yZjWdIv2lSB6 4jR941WL1Eny/7iiWt2xXcfYOCux0zkvEMICr3b+/n00B23zzKY49DiGT5BmczNiahQu 8Jvl0PFByystEHZR1Hb+a++87QQyv1Hh3/XhOQy06R6kxxtHB2yQgOyFr4rYiy0drhXL WpId3iObWyp/EMcYhUkd8+hDdPS5Mr6w/rQY9bQ1m0XvszwA0bP7zmPyo+f3AnVb2blE nlNQ== X-Gm-Message-State: AOJu0YzLjKu+BG3Qg5mgqMz0aLHFlWooj+OaZk+a7noG9251ziQJriEZ NI6IqUPiVRP6kVmd/Z4JG4XwiX1mCsyagnYlKmViU3sB4wYBWOKWZ7w6aEe63yWAsHM+zYBSIqJ OjdIC7MvStuZBkalZnpqkgolfAku8aT9+/MQlrg== X-Google-Smtp-Source: AGHT+IFwSVPFpVqf17hBg2XriUqZfUDGRKDnUXLHV/mfgZiIXsES4lHOr2Qzl5BQUTr2+ByJ1gvRt9Iw5bd4ejRxt3I= X-Received: by 2002:a0c:fcce:0:b0:6b7:8c94:cd15 with SMTP id 6a1803df08f44-6bb91d61b3dmr257457836d6.10.1722883767333; Mon, 05 Aug 2024 11:49:27 -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> <896ef99559e4e71d8f1c3abc47415b37ae325e55.camel@ageofdream.com> In-Reply-To: Date: Mon, 5 Aug 2024 20:49:16 +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 3:33=E2=80=AFPM Nick Lockheart wrote: > > This is a different problem that could be solved by a sandbox API. Not sure which case we were talking about then. ClockMock is what I've been referencing all along. > > Well, ok. But then we're back to prefixing global calls, which > > defeats the purpose of the proposal. > > Global functions would only need a prefix `\` in the *very rare* cases > where local functions are set as the default. For most people, the \ > would be omitted, as globals would be set as default for unqualified > function names. Right. But apart from mocking, what are these cases? If performance were no longer an issue, "using global functions" just makes the language harder to use, removing the local fallback. "using local functions" may be useful in namespaced code making many calls to functions within the same namespace. In that case, it would probably be more useful to switch the lookup order back instead. If you want to pay zero performance penalty, you can prefix global calls with \. You'd need to do that with "using local functions" anyway. As for mocking: If the code needs to change either way, why not make it testable in the first place, e.g. through dependency injection for time()? At least this only requires changing the calls that are mocked, instead of all the calls that aren't. The main benefit of the approach from ClockMock is that your code (probably) doesn't need to change. I do think that the entire approach is hacky, and probably worth solving on a language-level, at least if possible without adding limitations to the engine. A good first start would be to know what functions are commonly mocked with this approach. Ilija