Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124212 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 B01D21A009C for ; Thu, 4 Jul 2024 03:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720062791; bh=JgeoTfsUVqKh7dLGQnjfIC3l61/zZGrft7MrFHAWAG4=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=lypJSC1dJT13qxbnkV8DguorL7crUGtSDqIiCmsBMPGnGoNHEmmUsRgwexYxTwCCP MTuPIeDwWp2qU2qtmysmVsZaheiA6jj3veVSKZC+kS//wCq6bd1Pbx+IsCRJbugK+j 9xoBmqKdepta+2KdfmmC/P0siS20JeOMHIBDSfud7nM0jzWi25iOgOiuvft+HT9NVc Wr96qOMHpdepCPlN1EOvFGZ9AQeNZkhYXFC4Pb/Yl7MSa+1fJ2UpGHqBDdGuixgCKT i1+B1VElpxgYvSf7Fanr3Fv7la9hCzzve5zsVPFONobip5iDSI+u57t+rcO4NQ3F0J 0WxXBmY5VQUig== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AA1FB180CE5 for ; Thu, 4 Jul 2024 03:13:10 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,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-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 ; Thu, 4 Jul 2024 03:13:10 +0000 (UTC) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6519528f44fso1733187b3.1 for ; Wed, 03 Jul 2024 20:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1720062707; x=1720667507; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=J8aH/dtMLKekyab2WiU7Shdlzay0BQ+VxZKisE1VSCY=; b=rclV+34KYVIxx6sxog4vAV3ZNPXmGdMfN5UpdckbX00LrzGI1Ds54yZa4JPN1FfP4z XUAeJiJdifKnGTrGlldyywFeNym9FGFH0nvEM/NOT/hWhSialodJMxz5mg7nhN6kuIeF tOfv4JzLJ4uHF0Gjtt7RgG3QlBS5rscyIFlH40L9dLyRp1RdYlH6jhPtWqu1ixjnAaCY Pw4FBS18PY4qpYMiBKYnu1Sqr8euFyVUGy/+KSUe+Ib4jC1WjV9NszAK9MmkjJKR4NjO kQ2ow/RPvphXLNZMt78Rju/+pIPe7sce77Y3bU2P+v4q2nsiSXLlxe7JXr4v+P9xdJDP BXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720062707; x=1720667507; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J8aH/dtMLKekyab2WiU7Shdlzay0BQ+VxZKisE1VSCY=; b=F5uH1YZHIqH2QIEbJj2cgbTWvyQKucc5aIVvbFK1MfWBicI1/U3nAm8SNPGnbmu40m UhkQ2UFOWSHc0qN6ProvExaYw2tIuKz/OR/L76qGeRFoo8v1akTzAtDdUjyoaxqB+P5l JiZ6WSZ39RVyBrGdAUEpP4XaVk9vu8MRHIsE846u3GeSzkJih039CPKX1/vdjT+olKto tvQKxBuYL1WoiDSAvlbcaZFvIXuK4iclLoID+4JzSxs+Anj+p0dgtCQUDlUmV0yrZZXJ N2/Pzepo+JKYxKzCjnQ4wwAZDxlCKOcJWKwbewbpH3Fcae6yLNfNOSQiRYJkuz+d0kFp tnzg== X-Gm-Message-State: AOJu0Yx8oJNuRCCML9n31gVaZ9900AeOXDPjwfN2yukEjW8Iu8FTPz4v D8lGFsLZXDsjKdfG60K2gevOpv8VAZVsuQpMn3Qzw5mAFiqa+arbXDZfWWelkqEwhwXt1qH6CNl TXno= X-Google-Smtp-Source: AGHT+IGSxolZTYBMu1AYtLPw7ZmQMNLaGAGvju463+lLNQent0DwJZ7mhBdr12wthMuMVtdv0L1cyw== X-Received: by 2002:a05:690c:7090:b0:64a:7040:2d8e with SMTP id 00721157ae682-652da44ddf6mr5146577b3.33.1720062707286; Wed, 03 Jul 2024 20:11:47 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 00721157ae682-64a99c7196fsm23888807b3.3.2024.07.03.20.11.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 20:11:46 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] [PHP-Dev] Versioned Packagers (Iteration IV) In-Reply-To: Date: Wed, 3 Jul 2024 23:11:45 -0400 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <0E11F373-99DC-496E-9BBC-2F8688B9F66A@newclarity.net> References: <09559430-4477-4516-8D78-6F4071E1AA6C@newclarity.net> <0182F3D6-F464-477F-9029-A2D0A8B50C71@koalephant.com> <1AFD7AAE-8BEA-460D-88A8-15BB3D30A775@koalephant.com> <7B633CC7-C768-4852-A4D0-B252A04F7DE1@newclarity.net> To: Michael Morris X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Jul 3, 2024, at 10:31 PM, Michael Morris = wrote: >=20 > On Wed, Jul 3, 2024 at 9:56=E2=80=AFPM Mike Schinkel = wrote: >=20 > There are ~6300 uses of the keyword `import` on GitHub: =20 >=20 > = https://github.com/search?q=3Dimport+language%3APHP+symbol%3A%2F%5Eimport%= 24%2F&type=3Dcode >=20 > That's a lot of BC breakage for some people. >=20 > No worse than PHP 7's keyword introductions. True.=20 OTOH, if you don't actually have to break BC for discretionary changes, = then it would be better not to. >> Import's behavior is most similar to require_once, but it doesn't = have to be the same. Since it is a new entrypoint into the engine the = way the engine considers the code can be different - whether slightly = different or radically different is a debate for another time. I'm going = to stick with only those changes that make sense in the context of = package links. >=20 > When you first proposed modules I was understood (wrongly?) that you = were proposing imports to be a statement that imported into file scope = and then at the end of loading the file PHP would flush those symbols = just like how (I think?) JavaScript imports work (I am ignoring the = complexity closures add to simplify our discussion here.) >=20 > That was the first iteration, yes. I am adjusting to the feedback on = the list. JavaScript does imports the way it does because of how files = scope, and how the module system itself scopes, which isn't readily = retrofitted onto PHP. I think it *can* be retrofitted to PHP, but that is a different issue = and I won't derail your discussion to suggest it in this thread. > Also, at the time I was toying around with the format and had yet to = hit upon the situation where it could be useful, that being versioned = files. > =20 > This sounds like you are saying `import` would (instead?) be dynamic = like `include*` and `require*` and any symbols loaded with `import` = would continue their lifetime until the program is finished or the page = is loaded, depending on how the program is run? >=20 > Yes, because that is how PHP itself does work under the hood, at least = for php file includes. How it would go about doing this when resolving = .so or .dll extensions is another matter. Does it have to be this way? = That's the hint I've gotten from the feedback but only a core = contributor with experience working on the engine could say for sure. > =20 > I ask because when I was envisioning page scope being added to PHP I = was also envisioning that PHP could perform more optimizations if the = new symbols only affected the currently loaded page. If you are = proposing beyond-page lifetime then that precludes this optimizations = which is not a deal killer but is a disappointment. >=20 > Whether the optimizations affect the file on load depends on what's = being optimized to be honest. There is still an opportunity here. Where do you see opportunity for optimization =E2=80=94 assuming your = vision of imports =E2=80=94 that is not already a potential for = optimization? > =20 >> Now we have \B\foo(); This makes it relatively easy to have two = different versions of the package running since in our own code we can = always reference the foo in the B namespace. But while that allows = limited package versioning, it doesn't solve the multiple extensions = wanting to use the new stuff problem outlined above. >=20 > Consider the following parts of an application: >=20 > 1. Bespoke app > 2. "Enterprise Reports" library > 3. Twig v3 used by "Enterprise Reports" > 4. "ProductsPro" library > 5. Twig v4 used by "ProductsPro" > 6. "PP2ER Connector" library >=20 > Given your scenario I guess you assume Enterprise Reports would import = Twig v3 as maybe `ER\Twig` and ProductsPro would import Twig v4 as maybe = `PP\Twig`, right? >=20 > Correct. > =20 >=20 > How does the PP2ER Connector use Twig? =20 >=20 > Depends on which one it wishes to use, \ER\Twig or \PP\Twig > =20 > Does it create it own `PP2ER\Twig`? What if the connector needs to = use the `ER\Twig\Environment` from ProductsPro with the = `Twig\Loader\FilesystemLoader` from Enterprise Reports where those = classes have private and protected properties that are simple not = composable, and especially not across versions. >=20 > I've never seen cross version mixing like you're describing so I = didn't take it into account. That said, the extant copies of those = classes will be variables, and hopefully not global variables. I have with WordPress plugins.=20 I wish I could say exactly what, where and when, but sadly that = knowledge was lost to the mists of time. > Or what it he app itself needs to use the functionality of both in a = way that requires access to `private` and/or `protected` property values = or methods across the two versions? >=20 > That isn't in scope for this discussion. The whole point of private = and protected scope modifiers is to restrict access by outside code. = Breaking through that can be done with the Reflection API in some cases, = but it isn't easy. I think you misunderstood me. I was not advocating reaching into = private or protected.=20 What I was saying is if one indirect dependency used v3 and another = indirect dependency used v4 then when there is private state the caller = is still unable to get them to interoperate. =20 Or more simply, indirect dependencies are likely to cause problems when = interoperability is needed that are not directly in the dependency = chain. OTOH, it may be rare enough that we can say "Sucks to be you" if someone = needs that interoperability. =C2=AF\_(=E3=83=84)_/=C2=AF >> So we have to call out the version in code, like so. >>=20 >> import 'file.php v1.0.0'; >=20 > Where will PHP be able to get the version number in a performant = manner? >=20 > A question for another day. Frankly if your proposal hinges on using version numbers to = differentiate then I think it is not something you can postpone = answering.=20 If there is not a good answer then the approach you are exploring is = moot, at least as far as I can see. -Mike=