On Wed, Jan 3, 2018 at 12:10 PM, Andreas Hennings <andr...@dqxtech.net> wrote:
> This proposal contains some interesting ideas, which I see as separate: > 1. A syntax to declare the type of local variables. > 2. A syntax to declare the type of object properties. > 3. Preventing local variables, object properties and parameters to > change their type after initialization/declaration. > > For me the point 3 is the most interesting one. > I think the other points are already discussed elsewhere in some way, > although they are clearly related to 3. > > Point 3 would be a BC break, if we would introduce it for parameters. > Current behavior: https://3v4l.org/bjaLQ > > Local variables and object properties currently cannot be types, so > point 3 would not be a BC break for them, if we introduce it together > with 1 and 2. > But then we would have an inconsistency between parameters and local > vars / object properties. > > What we could do to avoid BC break is to introduce > declare(fixed_parameter_types=1) in addition to > declare(strict_types=1). > For local variables and object properties, the type would always be fixed. > But for parameters, it would only be fixed if the > declare(fixed_parameter_types=1) is active. > > Maybe to make it less verbose, we could say declare(strict_types=2), > which would mean the combination of both those things? > Or some other type of shortcut. > I think we will have to think about shortcuts like this if we > introduce more "modes" in the future. > > There will be occasions where having an unfixed variable alongside normal ones will be desirable. > > > Currently the var keyword is used to formally declare a variable. > > Are you talking about local variables? > In which PHP version? https://3v4l.org/o0PFg > > Sorry, I'm confusing PHP for JavaScript. I forgot that the var keyword was only used in PHP 4 for class members. For some reason my brain assumed it was usable in a local scope. > Afaik, currently var is only used for class/object properties from the > time when people did not declare the visibility as > public/protected/private. > > > > If no type is specified, then "mixed" should be assumed, not "scalar". > Assuming "scalar" would be a BC break, and it would be confusing. > > Ok. I'm misusing the term scalar to mean "variable who's type can be changed at will depending on context." Sorry.