On Wed, 4 Sep 2019 at 18:09, Ben Ramsey <b...@benramsey.com> wrote: > > > Andreas Hennings wrote: > > > > In some other languages the mixed type is called "variant". > > https://en.m.wikipedia.org/wiki/Variant_type > > I mostly remember it from VisualBasic. > > Union types are probably better than specifying a variant or mixed type. At > present, parameters and properties with no type specified are mixed by > default. Nikita has just opened discussion on a new union types proposal in > another thread.
Nothing wrong about union types, but this is a different topic. A "mixed" or "variant" type is simply giving a name to what we already have. Like the invention of the number zero. Currently afaik a variable with a type specifier is simply a variant/mixed variable with type checking added on. Which means every variable has to store the current value type. In other languages, typed variables are implemented without the dynamic type information, and only the variant/mixed/union types need this additional overhead. If we introduce this to PHP in the future at some point, this would allow for some nice optimization. > > > > Fwentish Aelondes wrote: > > > > Hello internals, > > > > Zeev's idea to bring peace to the galaxy seems like a good idea, but > > impossible to implement in practice. > > > > But it got me thinking about how one might introduce static typing > > into a dynamically typed language w/out breaking BC. > > > > And then I had this crazy idea: > > > > //int > > $i = 0; > > > > //string > > $c = 'c'; > > > > //float > > $pi = 3.14; > > > > If static typing in php was *only* an opt-in kind-of-thing, would this > > work? Could the parser be built to identify 3 or 4 different keywords > > in comments and give warnings or fatal errors for type conversions of > > variables that have the type specified in the immediately preceding > > comment? > > Static analyzers (like PHPStan) already honor types specified in comments > above variables. > > /* @param int */ > $i = 0; > > > > Michał Brzuchalski wrote: > > > > IMO it's crazy idea and we should not change the way comments work > > especially inline comments which even aren't kept in opcache. > > > > I think better approach would be to put type in front of first variable > > declaration like: > > > > [type] $variable = $value; > > I think specifying the type in front of the variable is the best option, and > we have precedence for this with typed properties in PHP 7.4. > > > Cheers, > Ben -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php