Hi, Would this warrant a having mixed types? By making every variable of type "mixed" when no type is defined, regardless of what value it receives or is initialized with, this would make an opt-in system. This behavior would cater developers who prefer only strict types, only dynamic types, and those that want to type their code bit by bit without putting declares that affect whole files.
``` $foo = 'foo'; // same as mixed $oneHundred = 100; // difference being: // $foo is accepted when 'string' is typed in the signature // $oneHundred is accepted when 'int' is typed in the signature // no longer mixed, only accepts their defined type as value // and is accepted only as their defined type in signatures string $foo = 'foo'; int $oneHundred = 100; // does imply we might need custom type definitions in the future to not have to work with mixed typedef Stringable = string | MyToStringInterface; Stringable $foo = (bool) rand(0, 1) ? 'foo' : new MyStringableObject('foo'); ``` Note that this behavior would require making some decisions whether or not in the future this opt-in behavior should change when a default value is given, such as with C# and type inference when declaring a variable, based on its assigned value. Regards, Lynn van der Berg On Wed, Sep 4, 2019 at 8:12 AM Michał Brzuchalski < michal.brzuchal...@gmail.com> wrote: > śr., 4 wrz 2019, 05:52 użytkownik Fwentish Aelondes <fwent...@gmail.com> > napisał: > > > 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? > > > > Just a (crazy) idea. > > > > ---- Fwentish > > > 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; > > > BR, > -- > Michał Brzuchalski >