Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121511 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21375 invoked from network); 29 Oct 2023 19:49:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Oct 2023 19:49:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0AA3C180382 for ; Sun, 29 Oct 2023 12:49:29 -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,HTML_MESSAGE, 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-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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 ; Sun, 29 Oct 2023 12:49:28 -0700 (PDT) Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-4a4021adbc7so1442173e0c.2 for ; Sun, 29 Oct 2023 12:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698608967; x=1699213767; 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=8KXt8I9IoRIoKZy87x1mIS74WaN19W/J//F0/5cGms4=; b=cei0NyFo9DxXl+TGhjpMrUnR1LRqibq+Vna6l9XkmIwBJoOHzq6vNTHQbkj6RYxT2+ M/lnkGqwi6ZOusupgkseyyU+9SQ3uXgL77455/ButaRpn1qCn/DR7Uelmh2/qfBtZbOu 4H1oyy6K5Z4ni/rzL5SB1b7aZnCJcoMyJrEUk/UE+oODTApPG9NPEsT1c/FCCmLuTt6b lMSM1/HNYc/H6+XBFkMjmt7mviI6WPkFQTRqAxoSlc+kxAZtAlwSTpkomfgQ7s0ifxl1 rlBRqBMokwHTQA2jZGHUbXw8VF9cPon3m8EnCtmbs1PT527R3eDWoIIHgPC+FOfbrpNZ 3WYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698608967; x=1699213767; 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=8KXt8I9IoRIoKZy87x1mIS74WaN19W/J//F0/5cGms4=; b=Lick0BKg8ots1ayK4GHyPTwc7Z7LcMLSpx2WP4V6gxCpkowsd0C84oFHZJYYuLlJV9 rSQ80OPtreX+NOHLmtUZDhfGTiMMcJWPcil+70/8+0hQbk+T+udRjbYzG3DTIlqxDmMz EaVm4Wa/7di4d0octTpzqvuUOPgQLV6PbT0gW1e9fdPdtNvD/G/NkElu1qMMXv8+Z/pC am6dvFg5J8uvBFhw60A938KxkwjL1aZ8+lQTyQs5zl9lxWp8WUj7N7aefbpA5ybVg5ns +SmtoFpYSt38oJDrlYvOs/9xoyVOGGOn8GF5Toqgqp3oOdwIpZslGxHqoLy8NAebKW9+ hKDg== X-Gm-Message-State: AOJu0YxguI3fgJmos6VsKG/LQ2zXDHyX9nJ9cugvzG2+h0pECQNiN066 GTXWIGWKQjpnAALyDrc3ZN/hAYDyhq/CFMYmbgY= X-Google-Smtp-Source: AGHT+IFrksoiHJv1FAOpGd9SttnRVywJwwAybbDa45aqFHq8StYB6W142b6okfdoPKN0T0/G6gfaktCWHJGqNVKRXts= X-Received: by 2002:a1f:a792:0:b0:496:2e22:29e3 with SMTP id q140-20020a1fa792000000b004962e2229e3mr6679616vke.1.1698608967460; Sun, 29 Oct 2023 12:49:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6124:1f25:b0:387:f724:598b with HTTP; Sun, 29 Oct 2023 12:49:26 -0700 (PDT) In-Reply-To: References: Date: Sun, 29 Oct 2023 12:49:26 -0700 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: Mike Schinkel , Larry Garfield , php internals Content-Type: multipart/alternative; boundary="0000000000001e343a0608e03851" Subject: Re: Basic Type Alias From: oladoyinbov@gmail.com (Oladoyinbo Vincent) --0000000000001e343a0608e03851 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable So, who is going to help with the implementation :) On Saturday, October 28, 2023, Alexandru P=C4=83tr=C4=83nescu wrote: > Hey, > > So actually while reading this: > > On Fri, Oct 27, 2023 at 11:42=E2=80=AFPM Oladoyinbo Vincent > wrote: > >> And also, in order to group and namespace the Type Alias, i suggest we u= se >> `typedef`, like i specify in my last message, it will be like this: >> >> File A.php: >> >> ```php >> >> namespace Package; >> >> typedef MyTypes { >> >> type Numeric: int|float|null; >> >> type Chars: string|null; >> >> type Result: bool|null; >> >> } >> >> > I came up with an idea: > > In php we don't have inner/nested classes, like in Java. > But maybe at some point we could have. An inner class would help with > avoiding some extra files and autoloading, especially when that class wou= ld > be needed as private. > > Coming back to types, what if a type would be allowed to be defined on th= e > class level? > It would solve the autoloading problem as it would be loaded together wit= h > the class. > And I guess that in real-life, complex types are usually related to some > code using them, so I expect that identifying a class where the type to b= e > placed would not be hard. > And even if it would be difficult, There can always be a class named Type= s > that would have only type definitions. > > An example would look like this: > > namespace My\App; > class Types { > public type Numeric: int|float; > } > > And it could be used with: > > use My\App\Types.Numeric; > function castNumericToFloat(Numeric $number): float { > return (float)$number; > } > > or > > use My\App\Types; > function castNumericToFloat(Types.Numeric $number): float { > return (float)$number; > } > > or by using an import alias, of course. > > Maybe we can use this construct, along with allowing a type to be defined > in a normal way, a way that would not permit autoloading. > However, a way that would better fit code that is procedural and it can b= e > loaded in the same functions.php that some projects use. > > Allowing inner "types" on classes might be a bit more complex that I can > ever evaluate. > But it might open the door for inner classes and there are nice construct= s > that can be built using this. > > Regards, > Alex > --0000000000001e343a0608e03851--