title: Is it possible to explicitly declare the type of a local variable in PHP?
body: <p>I know it is possible to declare the type of function parameters, function return, and class attributes. (as demonstrated below)</p>
  <pre class="lang-php prettyprint-override"><code>class HasString {
      private string $value;
  
      public function getValue() : string
      {
          return $value;
      }
  
      public function setAttribute(string $arg0)
      {
          $this-&gt;value = $arg0;
      }
  }
  </code></pre>
  <p>However, the following will not work.</p>
  <pre class="lang-php prettyprint-override"><code>// Tested in PHP 7.4.1
  string $localVar = &quot;value&quot;; // Parse error: syntax error, unexpected '$localVar' (T_VARIABLE) in php shell code on line 1
  </code></pre>
  <p>Does php has a syntax that I can use to explicitly declare the type of a local variable?</p>
  <p>This would be useful to catch bugs where a variable receives an unexpected value, and to help the IDE identify the variable type when dealing with mixed or unspecified function returns.</p>