Re: [Discussion] Variable Type Declaration Before Usage

From: Date: Tue, 07 Nov 2023 13:41:39 +0000
Subject: Re: [Discussion] Variable Type Declaration Before Usage
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121606@lists.php.net to get a copy of this message
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

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


« previous php.internals (#121606) next »