You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int $i= 0;
$i= 'Test'; // Should throw an exception
How it can be implemented
($_w= newclass(0) { publicfunction__construct(publicint$value) { } }) ? $i= &$_w->value : null;
$i= 'Test'; // Cannot assign string to reference held by property class@anonymous::$value of type int
In the compiler, we could keep of the variables and instead of using references, emit $_i->value everywhere we encounter $i in the current block. This would also allow us to implement readonly local variables (like const in JavaScript):
We can only use types in the PHP type system, e.g. the above wouldn't work for array<int> for example.
Performance
Using $_i->value instead of $i timed in at 175 milliseconds instead of 127 for 10 million assignments - a very small decrease, which will mostly not be noticed.
The text was updated successfully, but these errors were encountered:
Inspired by https://externals.io/message/119470#119488 and https://wiki.php.net/rfc/local_variable_types
What we would like to achieve
How it can be implemented
In the compiler, we could keep of the variables and instead of using references, emit
$_i->value
everywhere we encounter$i
in the current block. This would also allow us to implement readonly local variables (like const in JavaScript):Limitations
We can only use types in the PHP type system, e.g. the above wouldn't work for
array<int>
for example.Performance
Using
$_i->value
instead of$i
timed in at 175 milliseconds instead of 127 for 10 million assignments - a very small decrease, which will mostly not be noticed.The text was updated successfully, but these errors were encountered: