Re: [Discussion] Variable Type Declaration Before Usage

From: Date: Mon, 06 Nov 2023 14:47:49 +0000
Subject: Re: [Discussion] Variable Type Declaration Before Usage
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121602@lists.php.net to get a copy of this message
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.
Hello Oladoyinbo, I'll contribute an observation, correct me if I'm wrong. In Python or Javascript it is not possible to declare types, as they are dynamic languages, similar to PHP. What you can do in Python is write type annotations, but it doesn't change its type at run time.
myVar: int = 5;
print(myVar); # The output is 5
myVar = 'Marcos';
print(myVar); # The way out is Marcos
myVar = True;
print(myVar); # The output is True
As for Javascript, it doesn't even have type annotations, you need to use JSDoc to document, or use Typescript to use types. Hug. --- Marcos Marcolin Software Engineer | PHP www.marcosmarcolin.com.br

« previous php.internals (#121602) next »