RE: [PHP-DEV] [RFC Discussion] Typed Properties
| From: | Zeev Suraski | Date: | Thu, 31 Mar 2016 13:01:41 +0000 |
| Subject: | RE: [PHP-DEV] [RFC Discussion] Typed Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92047@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Joe Watkins [mailto:pthreads@pthreads.org]
> Sent: Thursday, March 31, 2016 3:41 PM
> To: Dmitry Stogov <dmitry@zend.com>
> Cc: Björn Larsson <bjorn.x.larsson@telia.com>; Phil Sturgeon
> <pjsturgeon@gmail.com>; Krakjo <krakjoe@php.net>; PHP internals
> <internals@lists.php.net>
> Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties
>
> Morning Dmitry,
>
> > This should be a error. I also think, that "public" might be omitted,
> > and it should be possible to write "int $bar, $foo"
>
> Omitting public might be nice, but also totally separate, you should be able to
> omit it for untyped properties too.
>
> > You say - C, C++, Java, HHVM, etc - all made worse decision? OK
>
> No. C, C++, C#, and Java had a different decision to make.
I don't think the decision is fundamentally different. It's fundamentally very similar if
not identical.
> [public] int foo, bar;
>
> It is obvious that bar is an int in any of those languages precisely because it
> necessarily has a type.
>
> Why we should jump to the same conclusion, in a system where properties do
> not necessarily have types is not clear to me.
Because we're dealing with a single statement, and we already have the concept that a modifier
for that statement is enforced throughout the statement - I don't see how whether that modifier
is mandatory or not makes any meaningful difference. Having an access modifier affect the entire
statement, while a type modifier affecting only the variable next to it - is extremely inconsistent.
If
Private Person $p, Car $c;
works, why shouldn't:
Private Person $p, public Car $c;
Work as well?
In addition to being inconsistent, it also calls for poor coding practices - mixing typed and
untyped declarations in a single statement - as well as different types in a single declaration. In
that context, what drove other languages to pick their syntax and force developers to separate
declaration of different variables types into different statements - applies exactly in the same
manner for all other languages, us included.
Zeev