Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121516 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30540 invoked from network); 29 Oct 2023 20:36:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Oct 2023 20:36:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 86592180382 for ; Sun, 29 Oct 2023 13:36:02 -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, 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-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 13:36:01 -0700 (PDT) Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-7a79ad6431eso138491339f.0 for ; Sun, 29 Oct 2023 13:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698611761; x=1699216561; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rldM1/oWWPSXVSyDGXKQVZfqNsIgc0PevRhg1kvXrYQ=; b=DXmdTphxX/UEIX5dPpuShe+bN1wSP7P9j+1SsvDJDr9XyEBv75Bt2WtWpxNXWA6/Qs qAQskHp1LB1lGEHnZSexe0nmfMWrXGWYSWfPouQggKj0MAmxf+Uj4wSnNs1ejS5nYns1 YPFSWpGdQsP4ShYz/yqfvac7VDTUZyiBXW1M9JUKnSNWMPU6IUFujX2gSSESzg4lPnHU KVhpE3tTuxU/49f5iPAeH55+y6+LARgl15YsIx1zJ/jRYYLvZVgnqwxCvI9+fJzq7gyB cJP/dk7kI16Zf1PLCn3vvt8vhfhpU9JHA54D23tk2pgDSFOBv7LK8CPzoxF93DizWRJD 4IvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698611761; x=1699216561; h=content-transfer-encoding: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=rldM1/oWWPSXVSyDGXKQVZfqNsIgc0PevRhg1kvXrYQ=; b=um6myR+EwplCrf/E87+gz7qipBmaJW6IC1eYWSU0F7LY/64jAT2KDEoMgwKHjal3Ho eflyMOwTKY9qQL/gcVjw4GQ0n/LtX2fLCBS0lQZwVvXm+Zz4pJ/4CJTPP32hXQ28cB0C jkV68WlQi/tc3N3moEc+DPDUr/njpWiWM+CmarRBwJQ08fOu2ShMAAy4GnppvjgQU44K xsdag9iWN9dmMJXiF5g1z8PpNhDthR8UdXfDfrPFxBrVVBgdAOTs+cSoPFDYto2QMlSu xpdwLJJpjlONjg1EZGgS3HmyFsV9sYogJimR/OiupK72LE4ylyG89F6Ef/iLfSYR7Shs H4Rg== X-Gm-Message-State: AOJu0Yyv4ENuNv64zBjUtnZeDoHSTeDIC/hpECTENOWFixQgmGikwjId kLxxT/FbcBjAyNN+DlG1sHMs+3MD6B9NyU0iBM5IyzvmLoJdVA== X-Google-Smtp-Source: AGHT+IHptXMYr9Djd8/V/I6Plp2YQsiv2ArA2uKgjleTRmV75qf9Lmcb5i39aSK8P08UEgBYSyKwTDle4+CwYLuYB7Q= X-Received: by 2002:a05:6602:3ca:b0:7a9:e197:376f with SMTP id g10-20020a05660203ca00b007a9e197376fmr11591225iov.16.1698611761292; Sun, 29 Oct 2023 13:36:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 29 Oct 2023 21:35:48 +0100 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: Oladoyinbo Vincent , Mike Schinkel , Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: Basic Type Alias From: landers.robert@gmail.com (Robert Landers) On Sat, Oct 28, 2023 at 10:29=E2=80=AFPM 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 = use > > `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 My personal opinion is that file-based type aliases would be the best. It solves an immediate problem while introducing a problem most people will never have (needing to reuse the type aliases elsewhere). It allows them to be used in functions and classes, while also making code more readable but not opaque outside the file. For example, if there is a type called BigNumber that was an alias of GMP|int|float|string, outside the file, knowing the actual types in my IDE is more useful than "BigNumber" and doesn't require me to dig into the definition or even agree with the other file's definition of "BigNumber." I just need to know that I need to pass it one of those types from my own code. However, reading that file's code, I don't need to know the intimate details of the aliases to make it more readable. If we find ourselves constantly writing the same type aliases in a bunch of files, we only need to wait less than a year to implement "global" (as in, available once include'ed) in the very next version of PHP. Robert Landers Software Engineer Utrecht NL