Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125108 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 7EA751A00BD for ; Fri, 23 Aug 2024 07:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724399344; bh=9yg7vWVrZ+xSuLXdxrj06CEhuojnU7jUTGOkaSd8X3Y=; h=Date:From:To:In-Reply-To:References:Subject:From; b=mDXrcfOQ8yXDizrIOJbeUYS9/3/sG2kD/qKoPCoHLNYX0ofuqmB5yQnq+HtdscTAT Eogn9jL2EBlEpqOFNSjpNTKQLWv5lWE0OYaqZ821TI7QG67HLIp3wHe45Dubc+IQzh MDeiAIPmMZev6pE7OssT9Z1zmWG3TNk0Aggiid9MfNXiMcQYIh6ra24oNJn5RlnM4T Hd8rRxoIvw56aPZ0zwbAwg9+7VokkkxbGeov8dQaL0DcSDh3AzRgQ40UwdWyz05xCH hRs+IWqFK1jJT/XKQlDXfgvFj/vbLs2/xSB+2X+3Nf5x7PhKdt/RvMflsoSdQ0pY7R unwY6p3E+za9A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3BB9A18003E for ; Fri, 23 Aug 2024 07:49:03 +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,HTML_MESSAGE, 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 fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 23 Aug 2024 07:49:02 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 7570E138FF9C for ; Fri, 23 Aug 2024 03:47:11 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-03.internal (MEProxy); Fri, 23 Aug 2024 03:47:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm2; t=1724399231; x=1724485631; bh=cgBesVaP82 Z9e+Fb9R095ydpO5MuxVcBezmrp+DRvsc=; b=EzPgJ7g4f672wQDCIwc6E1ed2k Lbg5NmZKKoUA+H9KZjQbZ9bo3T4w5Yqn0t6QXppO+B5y7x8Am8oOEbNZMyEUMGyM c7+fmZqkPujsnTqW13W2Yiftp1HvT0Ou0q+5qze//UXODU0z4Dwr18zmmZK+/6WV C081NrnYjQYDxo7eY4jHwScEvs6slw8bf22MnZvh5826cMl2PZEG/33syVj5M7nY lq0Or8oOARFTN09lmHvDrkEgo7op+v9u5grT9hEfM57cti3o1kQLQkhle+rwNXAv qaEZpt2SxUT8Z2xOqmQzr9wTrjpil/uCPYLgHd/2vOcrsxKJMkoBe0nHcC4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1724399231; x=1724485631; bh=cgBesVaP82Z9e+Fb9R095ydpO5Mu xVcBezmrp+DRvsc=; b=puBNRhhKZJ6bs3z6W00Vr3aC4JJw0CfAz5bM9pHh2Ntx p/pcS6qGtxHbO0C36bu+54CdsXQrUQnLjhEIjXf5DquZQr6Ox7UYXQVPFgnH5gZV 5cSFVjLzdhCfPY2WcwHl36Gk/1H7/JmU3bBkEABc/cM1UgA7MqxDYnc+Lk/RMEqt YkhQF7F9fYLTkSVgajis+J03ZQlsSPhqOtbJFYqkiddoNkiWvxzovnzacXXMDPGB 5Tz0EVAOgSLMRX4SgGJsT98DEhb2sXLufd9DWzsbzuCiiXvvpEDOfF4qMQ3Jkb2e l+kuADP3TN4UKitAg2/nskqGFH9iOolMTKz00o6s+A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvuddguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggff fhvffkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdf uceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnheptdeuje dttefhueelhfdtleeiudetlefftdduleehffegtdeihefhleeijefgveegnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlh gvugdrtghouggvshdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1CA35780065; Fri, 23 Aug 2024 03:47:11 -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 09:46:47 +0200 To: internals@lists.php.net Message-ID: <790534cd-e158-4712-878c-642dfd0e2bad@app.fastmail.com> In-Reply-To: <880ffc27dc9b421407a670c75d5f5ba756870396.camel@ageofdream.com> References: <846D7756-712B-4A7C-9FC6-DB9F858836B8@rwec.co.uk> <880ffc27dc9b421407a670c75d5f5ba756870396.camel@ageofdream.com> Subject: Re: [PHP-DEV] [Concept] Flip relative function lookup order (global, then local) Content-Type: multipart/alternative; boundary=67bb2558584745f7915c552038e3eb41 From: rob@bottled.codes ("Rob Landers") --67bb2558584745f7915c552038e3eb41 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Aug 23, 2024, at 09:27, Nick Lockheart wrote: > On Fri, 2024-08-23 at 07:39 +0100, Rowan Tommins [IMSoP] wrote: > >=20 > >=20 > > On 23 August 2024 00:15:19 BST, Mike Schinkel > > wrote: > > > Having to prefix with a name like Foo, e.g. Foo\strlen() is FAR > > > PREFERABLE to _\strlen() because at least it provides satiating > > > information rather than the empty calories of a cryptic shorthand.=20 > > > #jmtcw, anyway. > >=20 > > I knew I'd regret keeping the example short. Realistically, it's not > > a substitute for "\Foo\strlen", it's a substitute for > > "\AcmeComponents\SplineReticulator\Utilities\Text\strlen". > >=20 > > Having a syntax for "relative to current" is incredibly common in > > other path-like syntaxes. The most common marker is ".", and ".\foo" > > is literally how you'd refer to something in the current directory > > under DOS/Windows. But unfortunately, we don't have "." available, so > > I wondered if "_" would feel similar enough. > >=20 > > Another option would be to find a shorter keyword than "namespace" to > > put it in front. "ns\strlen(...)" is an obvious step from what we > > have currently, but it's not very obvious what it means, so maybe > > there's a different word we could use. > >=20 > > Rowan Tommins > > [IMSoP] >=20 > Could be mistaken, but I think the way PHP handles namespaces > internally is sort of the same as a long string, rather than as a > tree/hierarchy. >=20 > ie. \AcmeComponents\SplineReticulator\Utilities\Text\strlen >=20 > is really like: >=20 > class AcmeComponentsSplineReticulatorUtilitiesTextstrlen { >=20 > public function __construct(){ >=20 > } >=20 > } >=20 > And the "AcmeComponentsSplineReticulatorUtilitiesText" just kind of > gets appended to the front when the class name is registered. >=20 > I haven't done work on the namespace code, but I recall reading this > somewhere recently. This is mostly correct, the only thing missing from your strings is the = `\` character. I believe this even happens during compilation. Meaning i= t sees your namespace/uses and then rewrites the function/class calls du= ring compile time. Thus an unqualified call is prepended with the curren= t namespace defined at the top of the file. If we were to go with any major change in the current lookup where it is= perf or nothing, this is what I would propose for php 9.0 (starting wit= h an immediate deprecation): 1. any unqualified call simply calls the current namespace 2. >=3D php 9.0: no fallback to global 3. < php 9.0: emit deprecation notice if falls back to global This is how classes work (pretty sure), so it would be consistent. Going the other way (global first) doesn't really make sense because it = is inconsistent, IMHO. Will it suck? Probably. Will it be easy to fix? P= robably via Rector. =E2=80=94 Rob --67bb2558584745f7915c552038e3eb41 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Fri, Aug 23,= 2024, at 09:27, Nick Lockheart wrote:
On Fri, 2024-08-23 at 07:39 +0100, Rowan Tom= mins [IMSoP] wrote:

> On 23 August 2024 00:15:19 BST, Mike Schinkel <mike@newclarity.net>
<= div>> wrote:
> > Having to prefix with a name lik= e Foo, e.g. Foo\strlen() is FAR
> > PREFERABLE to _\= strlen() because at least it provides satiating
> > = information rather than the empty calories of a cryptic shorthand. =
> > #jmtcw, anyway.

> I knew I'd regret keeping the example short. Realistically,= it's not
> a substitute for "\Foo\strlen", it's a subs= titute for
> "\AcmeComponents\SplineReticulator\Utiliti= es\Text\strlen".

> Having a sy= ntax for "relative to current" is incredibly common in
>= ; other path-like syntaxes. The most common marker is ".", and ".\foo"
> is literally how you'd refer to something in the curre= nt directory
> under DOS/Windows. But unfortunately, we= don't have "." available, so
> I wondered if "_" would= feel similar enough.

> Anothe= r option would be to find a shorter keyword than "namespace" to
> put it in front. "ns\strlen(...)" is an obvious step from wha= t we
> have currently, but it's not very obvious what i= t means, so maybe
> there's a different word we could u= se.

> Rowan Tommins
<= div>> [IMSoP]

Could be mistaken, but I t= hink the way PHP handles namespaces
internally is sort of = the same as a long string, rather than as a
tree/hierarchy= .

ie. \AcmeComponents\SplineReticulator\Uti= lities\Text\strlen

is really like:

class AcmeComponentsSplineReticulatorUtilitiesTexts= trlen {

   public function __cons= truct(){

   }

<= /div>
}

And the "AcmeComponentsSplineRe= ticulatorUtilitiesText" just kind of
gets appended to the = front when the class name is registered.

I = haven't done work on the namespace code, but I recall reading this
somewhere recently.

T= his is mostly correct, the only thing missing from your strings is the `= \` character. I believe this even happens during compilation. Meaning it= sees your namespace/uses and then rewrites the function/class calls dur= ing compile time. Thus an unqualified call is prepended with the current= namespace defined at the top of the file.

= If we were to go with any major change in the current lookup where it is= perf or nothing, this is what I would propose for php 9.0 (starting wit= h an immediate deprecation):
  1. any unqualified call simpl= y calls the current namespace
  2. >=3D php 9.0: no fallback t= o global
  3. < php 9.0: emit deprecation notice if falls back= to global
This is how classes work (pretty sure), so = it would be consistent.

Going the other way= (global first) doesn't really make sense because it is inconsistent, IM= HO. Will it suck? Probably. Will it be easy to fix? Probably via Rector.=

=E2=80=94 Rob
--67bb2558584745f7915c552038e3eb41--