Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124237 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 16A2D1A009C for ; Fri, 5 Jul 2024 22:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720218495; bh=vdUrOXNd2H8mfZMO4q2zbTX9eBn7kaEx6qRfAMFet1g=; h=References:In-Reply-To:From:Date:Subject:To:From; b=Bxa3acuL7cKxMu0yXclY8DCfOdQcnPA7nBMimnPBD1scPqelUH0JcFogN5fjCAu/W wvABmgqWeRZ3nPiUUGEyTBPPWrljuYsKI64WGpH17roA3vA/tPSWrIpmuoKBIs4Rrx yzSxJXXgqwOug5LPuUV9JOIsumNbKo68IbX25EOgT2PkcYHFb+y7koFOxYJvIsAeP6 2Reb4UNt2n3MJobhbrMYGXShW08T/pnYga7MFWzaPVqEcofHOvk/JfNA/8VuxVGnQt 73fM/3fsodM80WCipv8TkZthhmyiOV0s2wH5L9bW3mWeTlxB/Y93vM5BPG7FvzXA6p i8MFnW+ZO38Qw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 45C9A180082 for ; Fri, 5 Jul 2024 22:28:15 +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, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) 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 ; Fri, 5 Jul 2024 22:28:14 +0000 (UTC) Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6b56000f663so11642226d6.1 for ; Fri, 05 Jul 2024 15:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720218411; x=1720823211; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=QHuHl2LbzHlb7+IDiOu3OPSlULfimhQq8DQAX5lKN2s=; b=MhuwtYfh7GseDHu9GczpyYOU9stkbuKsm3Bk4ZL1kuuV0jn6Ekk8OuqEonk/cEsr7j TsaRwb/O6FoAlATkzdA5gGzB6ocuiVnu9jnmFFhNo7IES5YV0C6TyuEVp0qZTlQAoHKz PYqb/VU3FYfyPQGGSFR7P4glse+SprUVj/HUrTww03g7/igmjNr6uwa6l36DgAcFOFnX VtrOb87XmgicxHy1xTpp39WFmNqJsm9pf2TNZHFe/zMB2aClN+JZ0+ZqJECFRWzn6/wg wNvauUKW9Wp+5YuzE97SvT+R8JBfocDRw9cg9wqmdc/cwS9iMaTAfXq4hqVOTVF51KNj ELvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720218411; x=1720823211; h=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=QHuHl2LbzHlb7+IDiOu3OPSlULfimhQq8DQAX5lKN2s=; b=deRTbkwedy48wNwi+UKsW0xWelHmVbq+FvC9Q9fPZ4INe4KaEei0pabLrtHakucI6A fhSI0SK1JOSVzwwEgFo5RfWoYyNoCDfiwR57f0jYsO9SslQprOpEKnniUv344csV25T2 48TajXWumLj9f5Vnpmh5EYD6Vga7e1qCkqQFElGG8hjxCHQ6NdA6IV45j4fUv/21J+l+ dlDHDc6NPE5krzG+Jmr/oG0jDJq9q431Kt7lC0+f2xn2wdsoRokPQFRzcqFv95kHb+hD qTmax+yzYxb14hjjnN3tMUZzFPCiFOka+Vn4Pc8KzFeicF8gpSQqbzzsqVBK9+9ycYWA LSzQ== X-Gm-Message-State: AOJu0YyMvfwVcM9X3A8SxtA63wJvBT+ixAYETjQxSh9hhAjt+has4jpv FdmVWYyHU8CxClL7eeNNUAeUWbjWHoQ3JCuvB+0f6/khHL4d+um8ydECuFY5NMLgCnlmD91+s3v cWn6YJkzm2adN6ePUjC+SZIDzKBkmvQ== X-Google-Smtp-Source: AGHT+IEppKF7UfQcWeg5UrSO8cdDnISYHIGnNyLszjPRWcneaQsftraYBVWc0mVoiNRpoetDOnT4NbQOxrqSc0TgxY8= X-Received: by 2002:a05:6214:3011:b0:6b4:e2e6:bd30 with SMTP id 6a1803df08f44-6b5ed083c2dmr75470446d6.62.1720218410780; Fri, 05 Jul 2024 15:26:50 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <09559430-4477-4516-8D78-6F4071E1AA6C@newclarity.net> <0182F3D6-F464-477F-9029-A2D0A8B50C71@koalephant.com> <1AFD7AAE-8BEA-460D-88A8-15BB3D30A775@koalephant.com> <91E36C29-758B-45E6-9765-5D8337E048A1@woofle.net> In-Reply-To: <91E36C29-758B-45E6-9765-5D8337E048A1@woofle.net> Date: Fri, 5 Jul 2024 18:26:40 -0400 Message-ID: Subject: Re: [PHP-DEV] [PHP-Dev] Versioned Packagers (Iteration IV) To: PHP internals Content-Type: multipart/alternative; boundary="0000000000004f914f061c878f3d" From: tendoaki@gmail.com (Michael Morris) --0000000000004f914f061c878f3d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 5, 2024 at 2:23=E2=80=AFPM Dusk wrote: > > To that end - consider the following. Let's say that two different files > in your project import different versions of package Foo. Foo contains a > definition of the FooBar class, and contains functions which return that > object. > > 1) If $foobar is one of those FooBar objects, what does $foobar::class > return? Depends on where it was imported to. The current system ALWAYS imports to the root namespace. This new system can import there, but also to another namespace. This was outlined in my previous email. For @A\Foo\FooBar the import will put FooBar at \A\Foo\FooBar, and that's what class will return. @B\Foo\FooBar will bind it to \B\Foo\FooBar and that will be the return of the class constant within the class. > Is it the same as the fully qualified name of FooBar (e.g. "Foo\FooBar")? > Does the result differ depending on what file contains that code? > Again, it depends on which package namespace the code was imported into. Foo\FooBar isn't a fully qualified name even in current PHP. Fully qualified names start with \, so the fully qualified name is \Foo\FooBar provided it was included into the root namespace. > > 2) What happens if you try to pass that string back to something like new > $class() or construct a ReflectionClass for it? Does that depend on the > location of the call? What if the call is through something like > PDO::FETCH_CLASS which occurs within the runtime? > Again, which package are we in? > > 3) Within Foo, would it be true that if $x =3D new FooBar(), then $x::cla= ss > =3D=3D=3D FooBar::class? Yes. > Does this differ outside Foo (with an appropriately qualified name for > FooBar)? > That's tricker, because the namespace matters in a way that it doesn't matter now. Given an import mapping of "@A\FooBar" then namespace A; $x =3D new FooBar(); $x::class =3D=3D=3D FooBar::class // true, however... echo $x::class // \A\Foo\FooBar That holds true even if FooBar's declaration file doesn't invoke any namespace. > > 4) If those two files both create FooBar objects of their respective > versions, what happens if you try to pass one of those objects to a > function in the file using the "wrong" version of Foo? Does it pass type > checks, and what happens if it does? If not, how does the check fail? > Each package has its own Foo\FooBar. They won't be interoperable even though they arise from the same code. If they should be or need to be interoperable then PHP will have to gain a notion of package beyond what's been scoped out here. > 5) What shows up in the output of functions like get_declared_classes()? > Are there multiple instances of FooBar in there for each version? How are > they distinguished from one another? You'll get \A\Foo\FooBar \B\Foo\FooBar If you also directly load Foo\FooBar into the root namespace using the composer autoloader you could also see \Foo\FooBar --0000000000004f914f061c878f3d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Jul 5, 2024 at 2:23=E2=80=AFP= M Dusk <dusk@woofle.net> wrote= :

To that end - consider the following. Let's say that two different file= s in your project import different versions of package Foo. Foo contains a = definition of the FooBar class, and contains functions which return that ob= ject.

1) If $foobar is one of those FooBar objects, what does $foobar::class retu= rn?

Depends on where it was imported to.= =C2=A0 The current system ALWAYS imports to the root namespace. This new sy= stem can import there, but also to another namespace.=C2=A0 This was outlin= ed in my previous email.

For @A\Foo\FooBar the imp= ort will put FooBar at \A\Foo\FooBar, and that's what class will return= .=C2=A0=C2=A0@B\Foo\FooBar will bind it to \B\Foo\FooBar and that will be t= he return of the class constant within the class.

<= div>=C2=A0
Is it the= same as the fully qualified name of FooBar (e.g. "Foo\FooBar")? = Does the result differ depending on what file contains that code?

Again, it depends on which package namespace the= code was imported into.=C2=A0 Foo\FooBar isn't a fully qualified name = even in current PHP. Fully qualified names start with \, so the fully quali= fied name is \Foo\FooBar provided it was included=C2=A0into the root namesp= ace.
=C2=A0

3) Within Foo, would it be true that if $x =3D new FooBar(), then $x::class= =3D=3D=3D FooBar::class?

Yes.
= =C2=A0
Does this dif= fer outside Foo (with an appropriately qualified name for FooBar)?

That's tricker, because the namespace matte= rs in a way that it doesn't matter now. Given an import mapping of &quo= t;@A\FooBar" then

=C2=A0 namespace A;
=C2=A0=C2=A0
=C2=A0 $x =3D new FooBar();
=C2=A0 $x::= class =3D=3D=3D FooBar::class // true, however...
=C2=A0 echo $x:= :class //=C2=A0 \A\Foo\FooBar

That holds true even= if FooBar's=C2=A0declaration file doesn't invoke any namespace.
=C2=A0

4) If those two files both create FooBar objects of their respective versio= ns, what happens if you try to pass one of those objects to a function in t= he file using the "wrong" version of Foo? Does it pass type check= s, and what happens if it does? If not, how does the check fail?

Each package has its own Foo\FooBar. They won'= ;t be interoperable even though they arise from the same code. If they shou= ld be or need to be interoperable then PHP will have to gain a notion of pa= ckage beyond what's been scoped out here.
=C2=A0
5) What shows up in the output of functions like get_declared_classes()? Ar= e there multiple instances of FooBar in there for each version? How are the= y distinguished from one another?

You'l= l get
\A\Foo\FooBar
\B\Foo\FooBar
=C2=A0
If you also directly load Foo\FooBar into the root namespace using th= e composer autoloader you could also see \Foo\FooBar
--0000000000004f914f061c878f3d--