Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121500 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33444 invoked from network); 28 Oct 2023 20:29:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Oct 2023 20:29:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F0EBF1804B0 for ; Sat, 28 Oct 2023 13:29: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-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 ; Sat, 28 Oct 2023 13:29:26 -0700 (PDT) Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-5a7af20c488so27185597b3.1 for ; Sat, 28 Oct 2023 13:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698524965; x=1699129765; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Z8UnuO/RT1NazdFz/ko043pwDQfKegL2xzuoSKFCwig=; b=PBPAOI/BfPcr/RwneSIHcptDMzrocwWSqfW/Qb8FtNu4j8WrgIcR8d70NXwLJE8VKv 1Pfl8xaF3UKH8mJFTn4iQwzluVcVbYd/Sj+ePvoYPi/uuweRaj5qZi3ry/neHKcC9i14 G6e8gFK79GvnyEfaIzjogehrTpR7Fgp3/xzEq4GEjy10CLVhos2j4rgn4bkaDPncTtWb cwAD1pq75g7z8Z9RqF99xkYLRauF50CYQe5Swc3uEVQxtcTLFdxnR6ThMuoFPU+Cys0r rRUZDWJRdYW3lHvq1yCHObud2/XZb6PNgzE8vQi3qQd1J5dmCYkqAiOphSyVVHc9BCxf jRCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698524965; x=1699129765; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z8UnuO/RT1NazdFz/ko043pwDQfKegL2xzuoSKFCwig=; b=Uehu/8clySXB6uDztTIUVE6CeQuu2zBGFr5+208VO6nZlCZJoaZaKgKeQChyldx+Ul ZkQDehrvhOKIwVmmIydWHqUzJW2ks6BkjD+FhbhE4KgkXe/lDVr6rvkhpZQ5YrnvHX0Q 6lv6H88ANLv98gTQprdmbgCgfSpevk2ajdYUCRCSh6rmp7P1AetEhR/+hhtp/jh5GVdV GHOdtvciNQg3iB74L4ms2y+Fue//FpZUUq6VsdWZeJjBRzIZh4XSY62UceFQNczwLyT/ ncMOwn4ybyc/1Ru8AUdqK7l4RYs/NQGxcq/h76vVna1glrfIDuw1+rrHCvICsaieD7x7 72Cw== X-Gm-Message-State: AOJu0YyApYksq1r4SYUevbMnDn0xIOKnGyB8L5D9M7uYvQngAsshore0 aAtVZzjF3LeI1/sSwYEr5e46N5qZCGgVtmzgz49eBTZYB6gAug== X-Google-Smtp-Source: AGHT+IH5XAtVGR+V1yVuRvGUlJEPdqA+GlKuUUIOFLx2PCxd3yfStvdBUWQ9D6whJtTpFswDvvBB/K2JsMUl1PkvV8I= X-Received: by 2002:a5b:d4b:0:b0:d9a:f3dc:7d15 with SMTP id f11-20020a5b0d4b000000b00d9af3dc7d15mr5565423ybr.49.1698524965471; Sat, 28 Oct 2023 13:29:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 28 Oct 2023 23:29:08 +0300 Message-ID: To: Oladoyinbo Vincent Cc: Mike Schinkel , Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000358a640608cca92f" Subject: Re: [PHP-DEV] Re: Basic Type Alias From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000358a640608cca92f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 us= e > `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 would be needed as private. Coming back to types, what if a type would be allowed to be defined on the class level? It would solve the autoloading problem as it would be loaded together with 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 be placed would not be hard. And even if it would be difficult, There can always be a class named Types 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 be 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 constructs that can be built using this. Regards, Alex --000000000000358a640608cca92f--