Re: [Discussion] Variable Type Declaration Before Usage
| From: | Robert Landers | Date: | Mon, 06 Nov 2023 14:15:22 +0000 |
| Subject: | Re: [Discussion] Variable Type Declaration Before Usage | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121601@lists.php.net to get a copy of this message | ||
On Mon, Nov 6, 2023 at 3:08 AM David Gebler <davidgebler@gmail.com> wrote:
>
> On Sun, Nov 5, 2023 at 1:37 PM Oladoyinbo Vincent <oladoyinbov@gmail.com>
> wrote:
>
> > Hello Internals,
> >
> > I was wondering if php could introduce this feature or if any experienced C
> > dev here can work on the implementation of this feature.
> >
> >
> I think this is a much bigger issue than bikeshedding over syntax. The idea
> of typed variables has been discussed a few times in recent years but the
> roadblocks have been efficiency of any possible implementation, BC in
> respect of places type hinting can already be used and the overall
> usefulness / desirability of the feature. It's one of those things that's
> been filled in reasonably well by third party static analysis tools. Tbh
> I'd be more interested in an official static analyzer than more type checks
> at runtime.
It's also worth adding that many times, certain functions cannot be
chained elegantly or the nesting level gets out of hand, making
reusing variables a way to handle that:
$name = implode(' ', array_map(ucfirst(...), $name));
might be more readable to write as:
$name = array_map(ucfirst(...), $name);
$name = implode(' ', $name);
In this case, $name turns from an array to a string. Having to come up
with unique enough variable names just to satisfy type-checking would
be rather annoying (and it is in other languages).