Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129544 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 97AA31A00BC for ; Thu, 4 Dec 2025 11:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764846076; bh=/5bFdLDrwOAfzn6m3IctxiPnDkBLIMC3A12X+Z4RY30=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=i+SSnI8ajQNOyo0bTYjU9gOT038yJ1BikmqgoCkhNgpXOQs/wvWiM61DuhcUJQfun WEAt8ScQStQc4kFm5mmGw//r2zDXdQoJxsuVSCt+ARTO72u7QaDHaNoZAfwo1t9f22 wJlTWzoQ0SY2YrYhXbQZImcw3GEo8PKEU9+vveT67sBOqsQuALsOi4+2/CNwmRa5yn +YrPYv+SKXdGFRxTD5sFCbv75dCsbrUeJEOWUgcm7T1TMuA+I71NVubVVoB7F8mCKo m3doK6497SiFTwiJ96tYnKoSjsyvNzV+cOMed+L6EhkYafogFkIqdWV4cd1e3sZ8aY 81ObRIVsaeK8Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7C5F6180055 for ; Thu, 4 Dec 2025 11:01:11 +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,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 Dec 2025 11:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1764846064; bh=obQMYXqXZSeEI4mnVHSTjgyUUa9+8dP732v5Rz8yEq4=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=X3vOYrkkb5x2XfEP+RbJoaoBNh/C9bWA4qVygyUF1YOkp8njJyNyNyXnHuJ4+1gZ/ dIlN5KvvujcQNEOclN7JXnKzyBikBcQWs45eLzMIMPlw/274KnqPOZ5bBQy4XVXXxK xikRIqjr7H8oG9+polOdUXzvcfyDPcAxJk/T5cLtluZ720l1miKfRdHlFlLa04fwyy gcBnpQpKOjFQOvXwmd+25N+UXy1dVFWaGXwPsSyoFW1Au1bqOCHF7AbssKlCdZg4q7 9dns8QGd9uL35K0VgMlAgoSgwGk7Zs98GyPMIKxPqE5aZ82C6jo5VxenFT1BAfu5T1 vlpi3wXtGOgzA== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 04 Dec 2025 12:01:04 +0100 To: Rob Landers Cc: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] Type Aliases In-Reply-To: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> References: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> Message-ID: <962b89f28f16ae91db6745cb090ec1ea@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-12-02 23:23, schrieb Rob Landers: > I’d like to request your comments on type aliases (not to be confused > with typedefs) at https://wiki.php.net/rfc/typed-aliases I'm generally in favor of having type aliases available, provided that the design is sound. I believe there have been some discussions and efforts before and my understanding is that getting them to work with a sound design is complicated - or at least raises many edge case questions. As for your RFC, I have the following notes: 1. I also was wondering why the special `include types` syntax exists. You answered that in a sibling thread, but it should also be in the RFC. 2. I feel that the `include types` syntax doesn't really fit PHP with two consecutive keywords without any clear delimiters to indicate that the second keyword effectively acts as a parameter to the first keyword. 3. I'm seeing in the PR that `include types` must use a string literal. That should be mentioned in the RFC. I believe it's a significant limitation in the developer experience. 4. In combination with (3), you are effectively reliant on relative paths to include a types file. This raises questions about what the “base path” is. Is it __FILE__? Is it the include_path INI? Is it the cwd? 5. The “copy and paste” semantics of `include types` also results in backwards compatibility issues for libraries, because any time I add a new type alias to my type file, it could conflict with another type that the user of my library also needs. 6. The RFC doesn't explain where type aliases work. In the RFC I'm seeing parameter and return type declarations. What about: - Property Type Declarations - The right side of `instanceof` - `new TypeAlias()` The latter very likely doesn't work, but what will the error message be? Will it be a “class not found”? Will it be “Cannot instantiate type alias TypeAlias”? 7. How will type aliases appear in error messages more generally? Say I have: use type Foo|Bar as FooOrBar; function foo(FooOrBar $x) { } foo(1); // Will the error message reference FooOrBar or will it reference Foo|Bar 8. What about Reflection? 9. For nested aliases, how will that work with “DNF types”? Consider: use type Foo|Bar as FooOrBar; use type Baz&FooOrBar as BazAndFooOrBar; This would result in `Baz&(Foo|Bar)` which is not in DNF. ---------- That's all I can think of for now, but I believe it already shows that there are quite a number of questions that need to be answered and I feel that the answers to those questions are likely not going to be satisfactory by either resulting in a questionable developer experience or by preventing a clean implementation of the future scope (e.g. autoloading semantics). Best regards Tim Düsterhus