Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125122 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 306221A00BD for ; Fri, 23 Aug 2024 11:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724412632; bh=qxBnwY/jpImQ2SesPHUrLcF6Tvqi9KYJcfVCw7MymVU=; h=Date:From:To:In-Reply-To:References:Subject:From; b=BFEHOjo1qgsazi131jjM9fppjXmNXTgVeDGyJYKQVsrrxxlDkTmiZf76yXGb/p9GB sG88FCO+QXbk9ikfx3bt1W4w4SzuH3gMXRUZ2rk0D66zom9dzWlHCQ+8c/0y+T7yq2 OGNYxRXYdfuN+qg9TqIaLBlQ6LbYq92WdkvJEkRXDH21bkTUyUgX/WeuyCmjGoTCCA j/B2I+0Brbfxu3NAbMDSjRv/U1tFA2AmWFEDFT7kp5MNViHGQCDoyAuuU90zjQ17KB NelmcQ094jnFLjfJXaOi0U4iIre6JonW3t93dTy5wuZgb7wZ1OVeEL+3raoHHFc7PS bEjNUG0afJzWQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A82118006F for ; Fri, 23 Aug 2024 11:30:32 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 ; Fri, 23 Aug 2024 11:30:31 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 39B481151C24 for ; Fri, 23 Aug 2024 07:28:40 -0400 (EDT) Received: from phl-imap-10 ([10.202.2.85]) by phl-compute-03.internal (MEProxy); Fri, 23 Aug 2024 07:28:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1724412520; x=1724498920; bh=U5g/4gW8JPuM507i0LXaN4wWDGiMXyiacpqh6R2DeV8=; b= HgBnOQy0NW3YhveszadbOtCe5c/2Hb2vhL6NRGFSFtdw1rvm2raDGLfHJibGXHR+ x/UHIrkHRIIql+du1xwe/2mALDmtA0yOBcwJai6jA17vm9FZKO53KIZSj+rRYONr Ta7u1WZMX9P8oyUFA+8Gvcg/uE425ABe1x7RYF1bkI3viirvxelcePxVaOildf5l npC42DkZw3JBKxk4FIL0o/2xf93gjrXW9PZXe68Rm8ZmUbOG3kWSlCOSmmpVFkhx qxHGg6fPibCxNdWMKfs+7aihb0wRWH3CHAOkbBZ6QoGNij8rdheDbVbAryc7VGMs 8MlEcC4KBkS8k7PeSWyiwg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1724412520; x= 1724498920; bh=U5g/4gW8JPuM507i0LXaN4wWDGiMXyiacpqh6R2DeV8=; b=d eSysOgfROVukWuFGw+0Q2juIOdJNggMgy91wFVzsqRxbmsRNHpplTgZQ4Gb4ue/z /6OuHOJLLxrO6omRurPqPaszYUSTmjBJkHRmd15E0Awq13B/7+NK6yyS03J94vv2 lqxbxS3qK5QZD10fPaXSnL/yNf49njtPouMK7dtBx3NFAah9b+gdwKSKsxa0qjif tdPwJdQJQRbjq8bNjCNhwPirjSjB/g8xh6iqmKUJo2D7WJJRucuGHdBOGJCle4TL f54w29A92oDAyI5nNnlyk2wa8/gwNMsV5QObgh/j58iZmF1jUIVe+PtA7dfDB+xN xU5dzGRG0il1MWlDd5kUg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvvddggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefoggffhf fvkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhn shculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenuc ggtffrrghtthgvrhhnpeevjefgvdehffeuudelgfeutdehteefhedtffdthfetvedulefg ueeiteelffeuvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohep uddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhish htshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id DF97A3C0065; Fri, 23 Aug 2024 07:28:39 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 23 Aug 2024 12:28:13 +0100 To: internals@lists.php.net Message-ID: In-Reply-To: <53BD062A-4D7F-4E5D-852E-6D27641213A8@koalephant.com> References: <21D6F160-5EAE-44FA-907B-E1DAAC1B8D75@rwec.co.uk> <53BD062A-4D7F-4E5D-852E-6D27641213A8@koalephant.com> Subject: Re: [PHP-DEV] [Concept] Flip relative function lookup order (global, then local) Content-Type: text/plain Content-Transfer-Encoding: 7bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On Fri, 23 Aug 2024, at 10:58, Stephen Reay wrote: > In a world where global functions take precedence over local ones > because some people don't like writing a single \ character, > autoloading would be a moot point because if you preference global > functions you're implicitly telling developers they shouldn't write > namespaced functions, by making them harder and less intuitive to use. Sorry to reply to the same message twice, but as a concrete example, consider this code: // Definition namespace Acme\Foo; class Utils { public static function magic(string $x): int { return \strlen($x); } public static function more_magic(string $x): int { return self::magic($x) * 2; } } // Caller namespace Acme\MyApp\SearchPage; use Acme\Foo\Utils; echo Utils::more_magic($_GET['query']); Rewritten as namespaced functions, with current PHP: // Definition namespace Acme\Foo\Utils; function magic(string $x): int { return strlen($x); } function more_magic(string $x): int { return magic($x) * 2; } // Caller namespace Acme\MyApp\SearchPage; use Acme\Foo\Utils; echo Utils\more_magic($_GET['query']); With "unqualified names are global", but a new "_\" shorthand for "relative to current", the caller is completely unaffected, but the definition becomes: namespace Acme\Foo\Utils; function magic(string $x): int { return strlen($x); } function more_magic(string $x): int { return _\magic($x) * 2; } Note how the "_\" is used in all the same places as "self::" was in the "static class" version. With "unqualified names are local", the change is very similar, but "the other way around": namespace Acme\Foo\Utils; function magic(string $x): int { return \strlen($x); } function more_magic(string $x): int { return magic($x) * 2; } Regards, -- Rowan Tommins [IMSoP]