Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129716 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 lists.php.net (Postfix) with ESMTPS id 0940A1A00BC for ; Mon, 29 Dec 2025 16:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1767025299; bh=zqDyhj12SOpjMRr7oBfu4ZsNu7WTW1mYXSHmGfVWHNg=; h=Date:From:To:In-Reply-To:References:Subject:From; b=UOwEi9+95jxrayYHgBX5d5hja2td2yBhH/XCa4NojvmAZtndsojVR9rOGayGDRysO VOtL649rR/czL5g/FvoRNQqw1xAGMf1Soh/qqnGO4Tm/tyBGPLlzqB8JLgLSblMAsC /fPysil60NnuF1WKzbgPGBQODkt8m/k1q0WpCTTU4VwGBNnC+/te+krL/LKa0r1B0F G+UQZVj8n6q1ICHCTPX8v3zZ7p26/0GF6VfkuPMkEybE6kRJgQv1udrik78gQ5K/ek 8+R2tflyGFph3vbh3ekoefVyzG2uJR9PHUK28zPGBlADuL5+1VhqanRp+0X0S+xhrC oiHh5xqmNN1xw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CCE01180068 for ; Mon, 29 Dec 2025 16:21:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (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 ; Mon, 29 Dec 2025 16:21:38 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 24CF47A007C for ; Mon, 29 Dec 2025 11:21:33 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Mon, 29 Dec 2025 11:21:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=1767025293; x=1767111693; bh=v7bSeFCOIacvQ1cOyMMM7 YIO0GBboxNvZqGX0nStEu8=; b=T/dKSoveQQSCTr/U/zW7m/EkBsh6WhsKkI5YW gqe7NOjEu+qofqYN96jDrinB7KLubJcLaozekJuiNMMaMoxUKY0kdgLNILHcUyM2 IM1YaoXCRc5APhZs9gsCpijhnRm4Zj5zUQf+WzSMdJVV1kFYmtMapra/rqwRU+ho k5arDSXecD2VocYmNOlqEvk/OCk1nrAXfxpRKH5+DehxtmOm7iIGjjvnO6kZxewg vBibCio2vxbSkql56ad1l6r7put3OFAYKp6EYDvZl8UrotAmtKV4jYjhsyaPbQ8x Ir1PaPVp5YBv+ZUwk8dHonpmINIAwC2nSGxrz8Lo9qM3OyHFA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender :x-me-sender:x-sasl-enc; s=fm2; t=1767025293; x=1767111693; bh=v 7bSeFCOIacvQ1cOyMMM7YIO0GBboxNvZqGX0nStEu8=; b=o3ydxPdFHJ23mRSgQ 6jtIdCv9fkpkagvY724CvznoxEvvX+l5UYPxg7EDJcZSA7sPeuvK5unhJsj4hUQk EL2R6Mftnz0W7UAzY9gqlCiMLF+ny02UtcK41NgjkUKocjqbXeqtR6zOqaloCaLR JZkaR24WbsbHqa5NBpOcWFcBNFCuVXLCnCDsdWXbQvm4dIHE7aIEJFNU5W00ge99 K5OLwM37NkQjuPK5cvunkNu0rWUD9Usq0TQj4Vc+tfr+YlXyZntEqAy/Eo+zbrg/ z0n0nLJkxqMUVGn/n4wlkUaFpCPE53AsNoP5Tr0zqxu1hSifeLF5Os1l45IUvrwI CeYbw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdejjeeiudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtqhertdertdejnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhepuefgteeijeeuveffudelhffhtefhkeevtdeuvefgffdvfeei vdetgfehveetleffnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhgu thgvtghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 7E088700065; Mon, 29 Dec 2025 11:21:32 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AFUDl4r8TPkB Date: Mon, 29 Dec 2025 10:21:12 -0600 To: "php internals" Message-ID: <998d891b-d4f9-4fc1-9c71-d7607052506a@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [Discussion] Reflection-based constructor autowiring (scope clarification) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sun, Dec 28, 2025, at 3:39 AM, ANDR=C3=81S Zolt=C3=A1n Gy=C3=A1rf=C3=A1= s wrote: > Hello internals, > > My name is Zolt=C3=A1n Gy=C3=A1rf=C3=A1s Andr=C3=A1s (aka Zoli). I am = a long-time PHP=20 > developer, primarily working on large PHP codebases where=20 > constructor-based dependency injection is used extensively. > > Before preparing a formal RFC, I would like to clarify the scope and=20 > intent of a small, opt-in idea and gather early feedback from the list. > > The idea is to introduce a *minimal reflection-based constructor=20 > autowiring primitive* into the core, exposed explicitly via the=20 > Reflection API, for example: > > `ReflectionClass::newInstanceAutowire(array $overrides =3D [], ?callab= le=20 > $resolver =3D null): object > ` > This proposal is intentionally narrow. To avoid misunderstandings, I=20 > would like to clearly explain what the idea *does* and *does not*=20 > include. > > *Key points of the idea, explained in detail:* > > *1. Explicit opt-in (no change to the `new` operator)* > Autowiring would only happen when the developer explicitly calls the=20 > new Reflection API. > The semantics of the `new` operator remain unchanged. Existing code=20 > paths are not affected, and there is no implicit dependency resolution=20 > anywhere in the language. > > *2. No global container or service registry* > The proposal does not introduce a global container, service locator, o= r=20 > registry of any kind. > Each autowiring operation is local to the call site and bound to the=20 > current call stack. No global state is created or reused across calls. > > *3. No implicit interface-to-implementation mapping* > When a constructor depends on an interface or abstract class, the core=20 > does not attempt to guess or discover a concrete implementation. > Such mappings are inherently policy decisions and vary widely between=20 > frameworks. Instead, an explicit resolver callback is required if=20 > non-instantiable types are involved. > > *4. Scalar parameters require overrides or defaults* > Scalar and builtin parameters are treated as configuration values. The=20 > core does not read environment variables, configuration files, or=20 > globals. > As a result, scalar parameters must either have default values or be=20 > provided explicitly via the `$overrides` argument. > > *5. Interface and abstract types require an explicit resolver callback* > Interfaces and abstract classes are never instantiated automatically. > If encountered during autowiring, the core either delegates resolution=20 > to the provided resolver callback or fails with a clear exception. Thi= s=20 > keeps architectural decisions firmly in userland. > > *6. Deterministic circular dependency detection* > Autowiring necessarily builds an object graph. The proposal includes=20 > mandatory detection of circular dependencies within that graph. > When a cycle is detected, a deterministic and descriptive exception is=20 > thrown, rather than allowing infinite recursion or a stack overflow. > > *7. Request-scope caching of constructor metadata only* > For performance reasons, constructor metadata (parameter lists, types,=20 > defaults) may be cached for the duration of the request. > No object instances are cached, no lifetimes are managed, and no=20 > persistent or global caches are introduced. > > At this stage, I am primarily interested in feedback on whether this=20 > level of restraint is sufficient to keep the feature aligned with PHP=E2= =80=99s=20 > =E2=80=9Cmechanism, not policy=E2=80=9D philosophy, and whether there = are any immediate=20 > concerns regarding reflection, error handling, or performance. > > If the direction seems reasonable, I plan to follow up with a draft RF= C=20 > on wiki.php.net that incorporates the feedback from this discussion. > > Thank you for your time and insights. > > Best regards, > > Zoli I am unclear what advantage this offers over the status quo, or who the = intended user is. Is the intent to be "an alternative to existing DI co= ntainers" (in which case, what does it offer that would make me use it i= nstead of Symfony DI, PHP-DI, rolling my own, etc.), or is it "a tool th= at existing DI containers can use to be better" (in which case, how is i= t better than the existing options for them)? Those are two different g= oals that would have two different designs. For example, lazy object proxies already existed in user-space. However= , the amount of fugly code it required was high, so moving that logic in= to the engine where it could take advantage of engine-only features to p= rovide a far cleaner API and better performance was a win, and allows th= e removal of lots of fugly code from existing projects (when they upgrad= e). I'm not clear where such a win can be found with this proposal. --Larry Garfield