Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119900 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46889 invoked from network); 11 Apr 2023 08:48:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Apr 2023 08:48:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3A6601804D4 for ; Tue, 11 Apr 2023 01:48:24 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 11 Apr 2023 01:48:23 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id s8so4077673wmo.0 for ; Tue, 11 Apr 2023 01:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681202902; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=c3X4Z1le7QRxwUGGZQparjdMzDP+W/wKJIPPusakjOc=; b=UB1EoN9YZCCzGyeSq1GqZPPWYXzUkEZhZ03pBEy9mS9IRRaGN6UxI9udR9kflk4Z4B n5pDgVy+W8NTZdf9dEGK/nq/cf0XxWKL+SV7fcTv1ASnnatU0+pxqfPHFLNxlloLUhuR xo4N7UmMUTQIitVTfd5EG5tVQpvORo+L0lvGBpAvD8Aw+hszz7BE6+RM6htwuh5eyhje PQvxx1jh6qZtp3x+u638Npz9HvpQYNBIZjd8zb12KkGYrg6vic3I5KtqJSBNvjbC3Vn0 nZHMXFAVNhhOcmDsJb8Bhr1R6R7vMtQSf1g3wk7AVKsf/G3siRvOanjOWjM5G/31kOSQ Sv0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681202902; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=c3X4Z1le7QRxwUGGZQparjdMzDP+W/wKJIPPusakjOc=; b=kpsyos6jZgpm0pz3WcPQL+WkvuTwFNoO7ZZ8rQKfpTgbYSEcVmCrKusqUxtOg2QTQr sERWGjFSr122fJvWhPBR1SYJtCYrcbZV1mDZesSiChURcfB1KpAKsK2e+Mjc+itfIvAx 7HVJXt0WUQnRfcvTxol0Ce0KfoXqfWEqelk+FaQ0GDFvL1qMWvhyzMTqrauYS39Y0tz5 2kH0lV0TjvyJ1zGDS/wn//dPB1O1YK6h5Pvx7rzoL2J2+F+3A1MIuhxMdsU9NXmdJV/K cDh607S7DRgg7NQVss2jVAFo2DjLUyYCkYtnzTN92yItDC7TTdSlxaKSiFWe5BnCBg5V +M3Q== X-Gm-Message-State: AAQBX9fzfwEhNpXKUSe+A1TSTU4pqw6/XOclk82fsT1ZgqEs47o+qj9R MkwCTqiwkrqgYVFZC7MUF5WVyAA/ga8= X-Google-Smtp-Source: AKy350ZTJVarO5wBG889mJfZDW1Qyu+/r8D6CGhMDanmiOZm7cuK3YuXpJifS0gRAQeu7JvjcI/AUw== X-Received: by 2002:a05:600c:850c:b0:3f0:5ed7:f859 with SMTP id gw12-20020a05600c850c00b003f05ed7f859mr9026105wmb.7.1681202902407; Tue, 11 Apr 2023 01:48:22 -0700 (PDT) Received: from [127.0.0.1] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.gmail.com with ESMTPSA id u15-20020a05600c210f00b003ee20b4b2dasm16173751wml.46.2023.04.11.01.48.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 01:48:21 -0700 (PDT) Date: Tue, 11 Apr 2023 09:48:20 +0100 To: internals@lists.php.net User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <6FA5AA43-9738-4400-8D83-38FC2D464B82@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?US-ASCII?Q?Re=3A_=5BPHP-DEV=5D_=5BRFC=5D_New_core_autoloading_mec?= =?US-ASCII?Q?hanism_with_support_for_function_autoloading?= From: rowan.collins@gmail.com (Rowan Tommins) On 10 April 2023 13:17:04 BST, "G=2E P=2E B=2E" wrote: >Hello Internals, > >Dan and I would like to propose a new core autoloading mechanism that fix= es >some minor design issues with the current class autoloading mechanism and >introduce a brand-new function autoloading mechanism: >https://wiki=2Ephp=2Enet/rfc/core-autoloading Hi!=20 Thanks both for tackling this, I know function autoloading has long been o= n a lot of people's wish lists=2E A few thoughts: > As a result of the pinning, function_exists() will return true for funct= ions in namespaces that have been pinned to a global function=2E=20 The lookup pinning seems like the right way to optimise the implementation= , but I don't think it should be visible to user code like this - a lookup = for "strlen" in namespace "Foo" is not the same as defining the function "F= oo\strlen"=2E Consider this code: namespace Bar { if ( function_exists('Foo\strlen') ) { \Foo\strlen('hello'); } } namespace Foo { strlen('hello'); // triggers name pinning } namespace Bar { if ( function_exists('Foo\strlen') ) { \Foo\strlen('hello'); } } If I'm reading the RFC correctly, the second function_exists will return t= rue=2E I'm less clear if the call to \Foo\strlen will actually succeed - if= it gives "undefined function", then function_exists is clearly broken; if = it calls the global strlen(), that's a very surprising side effect=2E For b= onus points, the call to strlen that triggers pinning could be inside an au= toloader, making even the first function_exists call return true=2E Similarly, I think it should be possible to "unpin" a function lookup with= a later definition, even if no autoloading would be triggered=2E That is, = this should not be a duplicate definition error: namespace Foo; if ( strlen('magic') !=3D 42 ) { function strlen($string) { /* =2E=2E=2E */ } } > The use of the word class in the API is currently accurate This isn't actually true: classes, interfaces, traits, and enums all share= a symbol table, and thus an autoloader=2E I don't know of a good name for = this symbol table, though=2E Regarding the API, would it be possible to take advantage of nearly all au= toloaders only being interested in particular namespace prefixes?=20 Currently, every registered autoloader is run for every lookup, and most i= mmediately check the input for one or two prefixes, and return early if not= matched=2E I suspect this design is largely because autoloading came befor= e namespaces, so the definition of "prefix" wasn't well-defined, but going = in and out of userland callbacks like this is presumably rather inefficient= =2E Perhaps the "register" functions should take an optional list of namespace= prefixes, so that the core implementation can do the string comparison, an= d only despatch to the userland code if the requested class/function name m= atches=2E Thanks again for working on this! Regards, --=20 Rowan Tommins [IMSoP]