Am 05.11.2023 um 14:37 schrieb Oladoyinbo Vincent:
Hello Internals,

Local based variable declaration before usage is available in most
languages like javascript, python, and many more. php has this, but it's
only available while working/dealing with oop related.

Somewhat ironically, one could say that typed scalar variables are already supported,
albeit with a somewhat cumbersome syntax.

Instead of

 ```php

int $intVar;

```
you write

```php
class TypedInt {
    public static int $intVar = 0;
}
$intVar = &TypedInt::$intVar;

echo $intVar; // 0

$intVar = 3;
echo $intVar; // 3

$intVar = 'x'; // Fatal error: Uncaught TypeError
```

https://3v4l.org/GFNgp#v8.2.11

Greetings
Thomas Gutbier

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to