Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:122250
Return-Path: <oladoyinbov@gmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 72343 invoked from network); 24 Jan 2024 23:23:48 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 24 Jan 2024 23:23:48 -0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1706138672; bh=T0KEEYIexUkuVLMZBYLi91l3/UsF3XyWL+jR6HsXNyg=;
	h=In-Reply-To:References:From:Date:Subject:To:Cc:From;
	b=W6qjp+7jzb1gBYocXWluFn3md6oIrUXWHcHXcAf5MmdE7TVNzQH6wMCBZiihUflxS
	 kiKS0ALxU4dlDBTRWa01Hyf5VD1wRcTNBDgdu/LlXE9attUISweS79K5bkDYAfKBII
	 g/AvAvy/slDNM7wijHbOVDfO9lI1rGvCHXWc3C8BJiNzL9WxCQEfr0WTL1PDJqWW3Z
	 lUrAqTBeBfaWc3r/0MqK/0o2wCq9cntHAnZWPOMSo0wszthqjkQlYLp0V8zQjNlAJN
	 Xah2ApWR4EthF6S1T4d3i8q2yef1ap+zQpZUJz1ejYCIkgW9MFyc6EwEQWZlruvxlp
	 mI76KAcHPIktQ==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 0D9C918006B
	for <internals@lists.php.net>; Wed, 24 Jan 2024 15:24:32 -0800 (PST)
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net
X-Spam-Level: 
X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_05,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM,
	HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,
	SPF_PASS autolearn=no autolearn_force=no version=4.0.0
X-Spam-Virus: No
X-Envelope-From: <oladoyinbov@gmail.com>
Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47])
	(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 <internals@lists.php.net>; Wed, 24 Jan 2024 15:24:31 -0800 (PST)
Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3392d417a9fso2709554f8f.1
        for <internals@lists.php.net>; Wed, 24 Jan 2024 15:23:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1706138626; x=1706743426; darn=lists.php.net;
        h=cc:to:subject:message-id:date:from:references:in-reply-to
         :mime-version:from:to:cc:subject:date:message-id:reply-to;
        bh=7CIkojjzFw+DTIkYEJgbIGwiQS7K5JtykSOt86zWEMc=;
        b=e2RnDL9l/coXYHv/SqpCylIZrOpQ3ad2VIp1bXhCdm2K9oGsFZ6eDl+2LQA+CbZRo8
         xR5AchQ++NXXgW0O6HK6WKKl+omvktYmKm8xJKIjrOkFL+RPVKQHM8mnW4lZWiwTbnj9
         uTxuXyaYnpuUqVAEhIFHt8accI5SyQ4lD5lkxgoOtKlFfXYlfXoZ89l0l/f9q39QHycl
         EqJLzNqlBd4M6EaPTknZd6nhYraw2Z8ByAhXYsGiNGXlVFbPRPO3rdOxnfMUhlqv004e
         QuKtEVWfg7Uz6J0rPeGJNGe19ZmcCoN0zAmDcK0PjMweeXk5xN1SzaahnrVDgnRFpFsx
         +UDw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706138626; x=1706743426;
        h=cc:to:subject:message-id:date:from:references:in-reply-to
         :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=7CIkojjzFw+DTIkYEJgbIGwiQS7K5JtykSOt86zWEMc=;
        b=rTM55k6EzEQvGSlAGLZSWx2fZ5wvPgHAuxMLX+xg2nyt0doDjQtbs/JFWjeD4G4Spw
         MBARh1LU6HV4CnSzlK2RRT8kvtpqN5DzNXK40GJOyPI3AlBIizXFkw0oEYiVJIfHdTUw
         CZ9Tz2r68fnlag6jYdnhMrh5y5TSkc/2WkEJ0R+w7o5YCWDei5qRwQ1ZfbdbOKVm2Jcr
         QeYvmxYDgT5a0j+x3X1tXQuvKQGsBJARJKHDYMze44YBufI43SU6geLigc+hEelZq9jS
         2oBpge0zG4V29lBrb8hc9RBG1odxEZfLr+TmJZp7MRw2u3LOAHrIifeK7kvtG3zBE/Ko
         0BFQ==
X-Gm-Message-State: AOJu0YzVOk2Ot2XEO6YqsQGklvfCGXVm+pAJghwoiOFVJPJyZaBuZWWW
	5aUZILrnA4yxLTKHHSi/kmdSQsznzGBPzHIzoYih7bGZ1S0jWJwsSTrb20aX73WhE2uuCs+oBao
	tHRryq2Mm3IvmBv+vhn/qjbCfCmyPU1zjxKgFhg==
X-Google-Smtp-Source: AGHT+IGBOs49ExepAzuJ63b7mwS70ADFQ76vo5cFyKNNSpZpCpMDZwHt7ii++4gigB36vhWAAiWumcWqIQ4dkEawo18=
X-Received: by 2002:a2e:b527:0:b0:2cf:db8:bd60 with SMTP id
 z7-20020a2eb527000000b002cf0db8bd60mr48287ljm.71.1706138121565; Wed, 24 Jan
 2024 15:15:21 -0800 (PST)
MIME-Version: 1.0
Received: by 2002:a05:6022:257:b0:4c:4651:96c0 with HTTP; Wed, 24 Jan 2024
 15:15:20 -0800 (PST)
In-Reply-To: <10e7aed0-00b8-4140-a1e1-bb0a33e90938@app.fastmail.com>
References: <CAHXoPRtjsPzgpYnhB05hjdZo6Q-MDr4TUGbn9LQ77-hKVTCZOA@mail.gmail.com>
 <CAPTD5yEYmhOqgCUMykhup5Ug0CRWee--3HvWO7jutwaUWOaD=g@mail.gmail.com> <10e7aed0-00b8-4140-a1e1-bb0a33e90938@app.fastmail.com>
Date: Thu, 25 Jan 2024 00:15:20 +0100
Message-ID: <CAHXoPRtsXKP3Kyd5Ok96cq++pGTFFhSLtiB1FJUfKVgD1EFMQA@mail.gmail.com>
To: Larry Garfield <larry@garfieldtech.com>
Cc: Jorg Sowa <jorg.sowa@gmail.com>, php internals <internals@lists.php.net>
Content-Type: multipart/alternative; boundary="000000000000ac7901060fb93c6b"
Subject: Re: Basic Type Alias
From: oladoyinbov@gmail.com (Oladoyinbo Vincent)

--000000000000ac7901060fb93c6b
Content-Type: text/plain; charset="UTF-8"

I have been so busy lately, which gave me no time to work on the type alias
implementation. but I will be happy if anyone can volunteer/help in
implementing this feature so that it can be introduced in PHP 8.4 or 9.0,
as this will help optimise a lot of people and codebase out there.


On Monday, October 30, 2023, Larry Garfield <larry@garfieldtech.com> wrote:

> On Sun, Oct 29, 2023, at 9:52 PM, Jorg Sowa wrote:
> > I really like the idea and I would love to see it in PHP. I'm wondering
> > however, what would be the scope of the feature and how complex would be
> > designed type system. Examples I saw in this thread could be easily
> > replaced with union and intersection types (i.e. numeric as int|float).
> In
> > my opinion, there is a little benefit implementing in this shape making
> the
> > PHP core more complex.
> >
> > The two use cases of user defined types in PHP which would benefit a lot
> > IMO, would be:
> > 1. Typed arrays similar to Typescript.
> > 2. Semantic types which would increase the security of systems. Example:
> > type UserId = int;
> >
> > function setUserId_1(int $userId){}
> >
> > function setUserId_2(UserId $userId){}
> >
> > setUserId_1(5); // OK
> > setUserId_2(5); // TypeError
> >
> > setUserId_1(UserId(5)); // OK
> > setUserId_2(UserId(5)); // OK
> >
> > Kind regards,
> > Jorg
>
> Simple unions are the easiest to talk about in quick examples, but the
> real benefit of type aliases is in other cases, some of which they would
> enable.
>
> Example:
>
> I have a real parameter defined in my attributes library like this:
>
> \ReflectionProperty|\ReflectionMethod|\ReflectionClassConstant $subject
>
> And it appears several times, I believe.  That would definitely be nicer
> if simplified to an alias.
>
> Example:
>
> There's general consensus that callable types would be beneficial:
> callable(RequestInterface, string): string or similar.  But inline, that
> gets long and complicated fast.  Type aliases would allow simplifying that
> to
>
> type callable(RequestInterface, string): string as PropertyRetriever
>
> function foo(PropertyRetriever $c) { ... }
>
> Example:
>
> As in the above example, type aliases serve as documentation for callables
> or complex types, explaining what that complex ruleset actually means,
> semantically.
>
> Example:
>
> If generics or typed arrays ever happen, they'd probably be useful here,
> too.
>
> Note that using type aliases in a required-fashion is a different matter,
> and potentially not feasible.  Free standing variables are untyped, which
> means setUserId(UserId $id) could not require a UserId, because there's no
> way to define a variable as being a UserId, not an int.  While I can
> definitely see a value in that kind of restriction, in practice I don't
> think PHP is capable of it without vastly larger changes.
>
> --Larry Garfield
>


-- 
Best Regards,
O. Vincent

--000000000000ac7901060fb93c6b--