Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125076 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 1A35D1A00C8 for ; Tue, 20 Aug 2024 21:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724191140; bh=jkHF3YO0CGJfNKc5oa7HUqkDvem2F+1COTmeOuG45gg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hyzqMSpR/38J1jPaC0ld/pzzElDUHXRfmy/6lUKEVbFX/i9cFHAtR4kcNEninToyY Yc/VG7x8JEicvNwyYfbQuqXMXndyhrn7nsTmhLqqVFyE+0kqqFr2lxCokS36SB2ngp foJe15ULfHTqBppl2RGtCUNG19504ZViXJNOKSfaA7zQSE1Mu6HT8fOrq2nhcA2zGO eQ4t69qXxdawH8anWouKBnYg2qKFPvL11QBDLxdNt80uiusvGZFtMPYe3T+POWFP7o /veaS2TnQjZir4I1TusNilX0eie5419Fl7cyWd0i2GQVRmpUX7C2um80jY/0a0lvDT G/xtvUhc2U8yA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0262A180083 for ; Tue, 20 Aug 2024 21:58:58 +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=1.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_INVALID,DKIM_SIGNED,DMARC_MISSING,HTML_MESSAGE,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 sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (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 ; Tue, 20 Aug 2024 21:58:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1724191023; cv=none; d=zohomail.com; s=zohoarc; b=QtJDAjFR3ub755rMELEVRZN4liZZg538WV+mouWQkXF3fFZO1LoQ19cY6mPSA7lebUS+8NMTV/zTvmJ3lWobOo2lqkdlwU1dnf8aASPKPQ2TSmZDcqVZbw7vk6iBaIk4gss1utJh988ocSTQj46DbIDwb6MEXmUnh3EkVrF8mN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724191023; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=lphMFtny/CYdO/TVMRTSRy7FrVJ7jAr6SVjypjE6udE=; b=X9ZPnBOsqzo0xRYNzhcC5LAAMRvwQ5jGnsHiNipI1cjhR4E2xYHGxT/tFoUpGTw7SF7hsyArfVEb+vZ9rBR+A95ard5g72uEM4cRNZdFcPyy1TYAcKYQ4ZpZS6nwez+zczm5HrCu15dwFctPPgzQNnZBZjRygi3/mIuy8xLXrUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=faizanakram.me; spf=pass smtp.mailfrom=hello@faizanakram.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1724191023; s=zoho; d=faizanakram.me; i=hello@faizanakram.me; h=MIME-Version:References:In-Reply-To:From:From:Date:Date:Message-ID:Subject:Subject:To:To:Cc:Cc:Content-Type:Message-Id:Reply-To; bh=lphMFtny/CYdO/TVMRTSRy7FrVJ7jAr6SVjypjE6udE=; b=dSKvnJeBCRR7wfdgNA4AD4K1QsVsnzLUtOkU7u2gLEijp/DddzQtx8GADf1FHkEf yGN1IgUaEUgqbkrdTzHBxpPVlIsvjbypyH/6vgt1NbI8Xq1M3ma9SwG0+74wXnKG/KF llQe7wflUGlv6BON4gpdt0kVT6SoXL2zHJAUZ0Pw= Received: by mx.zohomail.com with SMTPS id 172419102159392.7700629181395; Tue, 20 Aug 2024 14:57:01 -0700 (PDT) Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e13cce6dc85so3973229276.2 for ; Tue, 20 Aug 2024 14:57:01 -0700 (PDT) X-Gm-Message-State: AOJu0YwXdle3BLhEL6Iu3xywcquZkBTSCiVXfkbVdAAuBSn6iu3izj13 nycueApo8JI3MS9I/pmp9MnL+Hveq5EZym430mji/1oGfR4ImxIAq9VrB3eBmqhl04hY/FPP2yo TsP5qbYWX8I9HbZL385au+7BNpZA= X-Google-Smtp-Source: AGHT+IFgK/8Ogvtuw3qET8owLrX9oyLJa9i7U1DDBmb87gsbXORdwVc4ufkNT9ef/K4h/3CSBDn1/yZ62pnadAqylTw= X-Received: by 2002:a05:6902:188c:b0:e0b:f922:a135 with SMTP id 3f1490d57ef6-e166541e0c6mr824532276.9.1724191020891; Tue, 20 Aug 2024 14:57:00 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 20 Aug 2024 23:56:50 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PHP-DEV] [Concept] Flip relative function lookup order (global, then local) To: Ilija Tovilo Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000053542c0620248148" X-ZohoMailClient: External From: hello@faizanakram.me (Faizan Akram Dar) --00000000000053542c0620248148 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Aug 20, 2024 at 11:34=E2=80=AFPM Ilija Tovilo wrote: > Hi Levi > > On Tue, Aug 20, 2024 at 5:14=E2=80=AFPM Levi Morrison > wrote: > > > > I have long been in favor of a larger BC break with better language > > consistency. Class lookup and function lookup with respect to > > namespaces should be treated the same. The difficulty is getting a > > majority of people to vote yes for this. Keep in mind that qualifying > > every global function is annoying but probably can be somewhat > > automated, and will bring better performance. So again, this improves > > the existing code even without upgrading. > > > > Yes, there would be complaints about it. Yes, there are probably some > > people or projects who wouldn't upgrade. I don't particularly care, as > > there are increasingly more operating systems and companies providing > > LTS support for long periods of time. Probably Zend.com will offer LTS > > support for the last PHP 8.X release, and possibly there will be some > > distro which also has it. I believe it's the right thing to do > > because: > > > > 1. It's faster. > > 2. It enables function autoloading in a similar manner to class > autoloading. > > 3. It's more consistent, and simpler to teach and maintain. > > > > It's rare that you get all of these together, often you have to make > > tradeoffs within them. > > The approach I originally proposed also solves 1. and 2. (mostly) with > very little backwards incompatibility. Consistency is absolutely > something to strive for, but not at the cost of breaking most PHP > code. > > To clarify on 2.: The main issue with function autoloading today is > that the engine needs to trigger the autoloader for every unqualified > call to global functions, given that the autoloader might declare the > function in local scope. As most unqualified calls are global calls, > this adds a huge amount of overhead. > > Gina solved this in part by aliasing the local function to the global > one after the first lookup. However, that still means that the > autoloader will trigger for every new namespace the function is called > in, and will also pollute the function table. > > Reversing the lookup order once again avoids local lookup when calling > global functions in local scope, which also means dodging the > autoloader. The caveat is that calling local functions in local scope > triggers the autoloader on first encounter, but at least it can be > marked as undeclared in the symbol table once, instead of in every > namespace, which also means triggering the autoloader only once. > > Ilija > Hi, I completely agree with Levi's perspective, aligning class and function lookup with respect to namespaces seems a very sensible option. It will improve consistency and pave the road for autoloading functions without quirks. The impact of fixing functions look up is overstated. For instance, PHP-CS-Fixer can add "global namespace qualifiers" to all global functions in a matter of minutes, it is not like people have to go through code and change it manually. To ease the transition, PHP can ship a small fixer with the next PHP version for changing global function usage (prepending \ or adding use statements) and be done with the inconsistency once and for all. Kind regards, Faizan --00000000000053542c0620248148 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Aug 20, 2024 at 11:34=E2=80= =AFPM Ilija Tovilo <tovilo.ili= ja@gmail.com> wrote:
Hi Levi

On Tue, Aug 20, 2024 at 5:14=E2=80=AFPM Levi Morrison
<levi.m= orrison@datadoghq.com> wrote:
>
> I have long been in favor of a larger BC break with better language > consistency. Class lookup and function lookup with respect to
> namespaces should be treated the same. The difficulty is getting a
> majority of people to vote yes for this. Keep in mind that qualifying<= br> > every global function is annoying but probably can be somewhat
> automated, and will bring better performance. So again, this improves<= br> > the existing code even without upgrading.
>
> Yes, there would be complaints about it. Yes, there are probably some<= br> > people or projects who wouldn't upgrade. I don't particularly = care, as
> there are increasingly more operating systems and companies providing<= br> > LTS support for long periods of time. Probably Zend.com will offer LTS=
> support for the last PHP 8.X release, and possibly there will be some<= br> > distro which also has it. I believe it's the right thing to do
> because:
>
>=C2=A0 1. It's faster.
>=C2=A0 2. It enables function autoloading in a similar manner to class = autoloading.
>=C2=A0 3. It's more consistent, and simpler to teach and maintain.<= br> >
> It's rare that you get all of these together, often you have to ma= ke
> tradeoffs within them.

The approach I originally proposed also solves 1. and 2. (mostly) with
very little backwards incompatibility. Consistency is absolutely
something to strive for, but not at the cost of breaking most PHP
code.

To clarify on 2.: The main issue with function autoloading today is
that the engine needs to trigger the autoloader for every unqualified
call to global functions, given that the autoloader might declare the
function in local scope. As most unqualified calls are global calls,
this adds a huge amount of overhead.

Gina solved this in part by aliasing the local function to the global
one after the first lookup. However, that still means that the
autoloader will trigger for every new namespace the function is called
in, and will also pollute the function table.

Reversing the lookup order once again avoids local lookup when calling
global functions in local scope, which also means dodging the
autoloader. The caveat is that calling local functions in local scope
triggers the autoloader on first encounter, but at least it can be
marked as undeclared in the symbol table once, instead of in every
namespace, which also means triggering the autoloader only once.

Ilija

Hi,

I completely agree wit= h Levi's perspective, aligning class and function lookup with respect= =C2=A0
to namespaces seems a very sensible option.
It w= ill improve consistency and pave the road for autoloading functions without= quirks.

The impact of fixing functions look up is= overstated. For instance, PHP-CS-Fixer can add
=C2=A0"globa= l namespace qualifiers" to all global functions in a matter of minutes= , it is not like
=C2=A0people have to go through code and change = it manually.


To ease the transition, PHP can ship a small= fixer with the next PHP version for changing
=C2=A0global functi= on usage (prepending \ or adding use statements) and be done with the=C2=A0=
inconsistency once and for all.


Kind regards,
Faiz= an

=C2=A0
--00000000000053542c0620248148--