Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129709 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 7614D1A00BC for ; Sun, 28 Dec 2025 09:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1766914804; bh=UlXrvo6G5/ah1COPq1zmvT3RUSVDWRDxcow+w1+/BwA=; h=From:Subject:Date:To:From; b=U8kyqRDxDUZUp3NymyNaUtkYJ53rLY5fs0p19lK1zLzFzYy9+yZ4txXMaAB1enpPO ind2jJ1IICqIysnhCkT4AyTWfvGDC/LqXZ/6pD+WOD/fxukX4ckkS9mWb+MJJIQ8Jk 4OoJUGKEeEC0Vzdhxl+y9Bts8C8tme3dT/HeEHr4OG4RMS5K6xs0/Re0Jxvm6VOFZ9 v+jkGEMxnSs0JCL/zlydcPvyuTUZVOSS6HaQWaRnA4drwRx/LBSRZ9FhJ3Q5s49sEH 3qlEh0JKikMROKDYmRv5y6dkKnDwYxS65Lf/NqkVMKKSevtV9O98vVHKQC0s77JAnF TC+SLpXIQmf8Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 145FA18004C for ; Sun, 28 Dec 2025 09:40:03 +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.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_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 ; Sun, 28 Dec 2025 09:40:02 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-b7eff205947so1176307966b.1 for ; Sun, 28 Dec 2025 01:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766914796; x=1767519596; darn=lists.php.net; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=V4A8MZ/bQ+GdHzdq9I1rFBhkLmVtnSj59wTcLo2yRl0=; b=GYyhH9D7RrmpgUhfk8+z+0ClPzGBoJgTbGjjE9jYM6+xWL7piPHBjiMOn4v0b4fcW+ gny0ViuZm7UWnymBDJmFc3AIc3TNEuMeHQAJN253XOLhids8J0bfE273yEZuQyAuqv++ MWC72oJg58THiBTbFNwIwtaflDNBpPuNrVG1spgWBnZOaB8sxYHEWCvhyXa3riEKhFLt 0ztiHIjQxSyGigUgsnYhQR+KVyvgCAp4YrOEsiHJ0sfM7cW/eJoFwES3p3aLb3MtW6XG wup2LfOrnhWbJdz9eCvLU+4PYsZ4CTiksj/ufUboCUFEXBVhzv0/A4UWzUSuvrGcC0W3 H8ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766914796; x=1767519596; h=to:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V4A8MZ/bQ+GdHzdq9I1rFBhkLmVtnSj59wTcLo2yRl0=; b=TZl42jJhmOT4TKzEOloLkXHuB+CJSfq9rMHPHQs9EwHikxvgmbMGkIkiaG0MM1Lij7 TS+0CisZ6cGbEfp0BnOmS0iFexIODPGthCtdAWtD1hSIPmAzymN9rTtJPOXFvel5nx88 fIcxJwgEOeUwdJ0Fs2CyYlRXev651D1315M1KBIYClwMIC0fidn6dpYFl8VTRpEPNDZ2 NV88ycJ/BLsXZ5qMjMdwqnbFJRckd/rDb/5uBdUVqi4wEWMQ4iUmE9iivQOUhbyqsDjv /jmzG9aom3FgscOl67249EYdGHHVotvIWSuAlOn7RvlUchE6uM3zHUy/5kAoiR4aVF9P /eHw== X-Gm-Message-State: AOJu0YzetJPU7WSUiVU5AraJ06Hm5mPN204SUaYrAw2djnE5beWxJFrb rYUComYlH7+LuKLx7Y8z1cATFr8ewnx3wzJTBrW8Asb9jtsUNMhtJOFgAEuL1Q== X-Gm-Gg: AY/fxX4mcIZ2LPsv7wgnvimqFQmg2WyyUXeVoV3z6LXmqXQeUwU9PeFuuIyh743Tp+0 EMRW9F7+ZVufzP0ZdarwXappbnClftizouuUq/9IKephYNgRi98dNeIN5pSL19HWqYMCHeL7WTg 5cTHgC8IxvTYyW5cx7xk3r10pftaXa/EmdCKP21cdjjk43OwZUADKNkAUonmaFtTnm4b9Myq/1c U0YZXTzSGUg7q6BHKfpNRKNX+01TqPbBR1IoiBWvSqc5e48BJ9xzvoGUkqv5zci3BDONgEGhZzi tvwNiOouhVzO4YCF92SYWYUE61a+0lg+sBtTFuroA4xOFB7Oeiw0Rmi/1BbbEAKA9JfIHs93Y5E v1fG9FRpIx5W35Yl6nwi4flbxgoWQpg3kBJua9O6AFLiy1uUHvT7NqOEDw87dUk+U32kCgOydHY mfowoqLGn7k/vljDWT1La/KF49akMzvqWtFA== X-Google-Smtp-Source: AGHT+IGKEI6vtlRlRuzoAcMw0g+JFKu1aYXbIvDcu7YMAg59jrjKcL93aDiJeW6+e+KYHBKrYyvR8A== X-Received: by 2002:a17:907:6e9f:b0:b73:8cea:62b3 with SMTP id a640c23a62f3a-b803704ffd7mr2792006066b.41.1766914796004; Sun, 28 Dec 2025 01:39:56 -0800 (PST) Received: from smtpclient.apple ([2a02:2f0c:c301:6900:7c01:33a4:e2da:5495]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b836b9b08c2sm209121766b.58.2025.12.28.01.39.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Dec 2025 01:39:55 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_3366265F-35AE-48F4-9DE9-CD85A809DB71" Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: [PHP-DEV] [Discussion] Reflection-based constructor autowiring (scope clarification) Message-ID: Date: Sun, 28 Dec 2025 11:39:44 +0200 To: "internals@lists.php.net" X-Mailer: Apple Mail (2.3826.700.81) From: azolee@gmail.com (=?utf-8?B?QU5EUsOBUyBab2x0w6FuIEd5w6FyZsOhcw==?=) --Apple-Mail=_3366265F-35AE-48F4-9DE9-CD85A809DB71 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello internals, My name is Zolt=C3=A1n Gy=C3=A1rf=C3=A1s Andr=C3=A1s (aka Zoli). I am a = long-time PHP developer, primarily working on large PHP codebases where = constructor-based dependency injection is used extensively. Before preparing a formal RFC, I would like to clarify the scope and = intent of a small, opt-in idea and gather early feedback from the list. The idea is to introduce a minimal reflection-based constructor = autowiring primitive into the core, exposed explicitly via the = Reflection API, for example: ReflectionClass::newInstanceAutowire(array $overrides =3D [], ?callable = $resolver =3D null): object This proposal is intentionally narrow. To avoid misunderstandings, I = would like to clearly explain what the idea does and does not 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 new = Reflection API. The semantics of the new operator remain unchanged. Existing code paths = are not affected, and there is no implicit dependency resolution = anywhere in the language. 2. No global container or service registry The proposal does not introduce a global container, service locator, or = registry of any kind. Each autowiring operation is local to the call site and bound to the = 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 = does not attempt to guess or discover a concrete implementation. Such mappings are inherently policy decisions and vary widely between = frameworks. Instead, an explicit resolver callback is required if = non-instantiable types are involved. 4. Scalar parameters require overrides or defaults Scalar and builtin parameters are treated as configuration values. The = core does not read environment variables, configuration files, or = globals. As a result, scalar parameters must either have default values or be = 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 = to the provided resolver callback or fails with a clear exception. This = keeps architectural decisions firmly in userland. 6. Deterministic circular dependency detection Autowiring necessarily builds an object graph. The proposal includes = mandatory detection of circular dependencies within that graph. When a cycle is detected, a deterministic and descriptive exception is = 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, = defaults) may be cached for the duration of the request. No object instances are cached, no lifetimes are managed, and no = persistent or global caches are introduced. At this stage, I am primarily interested in feedback on whether this = level of restraint is sufficient to keep the feature aligned with = PHP=E2=80=99s =E2=80=9Cmechanism, not policy=E2=80=9D philosophy, and = whether there are any immediate concerns regarding reflection, error = handling, or performance. If the direction seems reasonable, I plan to follow up with a draft RFC = on wiki.php.net that incorporates the feedback from this discussion. Thank you for your time and insights. Best regards, Zoli eng. ANDR=C3=81S Zolt=C3=A1n-Gy=C3=A1rf=C3=A1s --------------------------------------- tel: +40 745 797 798 mail: azolee@gmail.com --Apple-Mail=_3366265F-35AE-48F4-9DE9-CD85A809DB71 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Hello = internals,

My name is Zolt=C3=A1n Gy=C3=A1rf=C3=A1s Andr=C3=A1s = (aka Zoli). I am a long-time PHP developer, primarily working on large = PHP codebases where constructor-based dependency injection is used = extensively.

Before preparing a formal RFC, I would like to = clarify the scope and intent of a small, opt-in idea and gather early = feedback from the list.

The idea is to introduce = a minimal reflection-based constructor autowiring = primitive into the core, exposed explicitly via the = Reflection API, for = example:

ReflectionClass::newInstanceAutowire(array =
$overrides =3D [], ?callable $resolver =3D null): object

This proposal is intentionally narrow. To avoid = misunderstandings, I would like to clearly explain what the = idea does and does = not 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 new Reflection = API.
The semantics of the new operator remain = unchanged. Existing code paths are not affected, and there is no = implicit dependency resolution anywhere in the = language.

2. No global container or service = registry
The proposal does not introduce a global container, = service locator, or registry of any kind.
Each autowiring operation = is local to the call site and bound to the 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 does not attempt to = guess or discover a concrete implementation.
Such mappings are = inherently policy decisions and vary widely between frameworks. Instead, = an explicit resolver callback is required if non-instantiable types are = involved.

4. Scalar parameters require overrides or = defaults
Scalar and builtin parameters are treated as = configuration values. The core does not read environment variables, = configuration files, or globals.
As a result, scalar parameters must = either have default values or be 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 to the provided resolver callback or = fails with a clear exception. This keeps architectural decisions firmly = in userland.

6. Deterministic circular dependency = detection
Autowiring necessarily builds an object graph. The = proposal includes mandatory detection of circular dependencies within = that graph.
When a cycle is detected, a deterministic and descriptive = exception is 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, defaults) may be cached for the duration of the = request.
No object instances are cached, no lifetimes are managed, = and no persistent or global caches are introduced.

At this stage, = I am primarily interested in feedback on whether this level of restraint = is sufficient to keep the feature aligned with PHP=E2=80=99s = =E2=80=9Cmechanism, not policy=E2=80=9D philosophy, and whether there = are any immediate concerns regarding reflection, error handling, or = performance.

If the direction seems reasonable, I plan to follow = up with a draft RFC on wiki.php.net that incorporates the feedback from = this discussion.

Thank you for your time and insights.

Best = regards,

Zoli


eng. ANDR=C3=81S = Zolt=C3=A1n-Gy=C3=A1rf=C3=A1s
---------------------------------------tel: +40 745 797 798
mail: azolee@gmail.com

= --Apple-Mail=_3366265F-35AE-48F4-9DE9-CD85A809DB71--