Perhaps it's time to revisit the idea of allowing variables to have their
types locked down. The keywords needed are already reserved. So...

string $a = "hello";
int $b = 5;

Once declared this way the variable's type won't change unless it gets
unset. In normal mode PHP will coerce any assignment to the variable to the
desired type. If declare strict types is on then assigning the wrong type
to a variable would raise a type error.

Note this would simplify one of the use cases of setters - insuring the
class member is of a valid type.

The idea of function overloading reminded me of this. I'd consider being
able to do this sort of type lockdown to be prerequisite to having
overloaded functions.

Since this approach is entirely opt in I don't think it would make the
language harder to learn.

Reply via email to