title: Syntax for object creation specification?
body: <p>PHP uses keyword <a href="https://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new" rel="nofollow noreferrer">new</a> to create an instance of given class. The description in PHP manual seems rather vague, find it unclear what syntax is allowed here. Which tokens/expressions can be passed to <code>new</code>.</p>
  <pre><code>class Foo {}
  
  // using class identifier obviously works
  new Foo();  // =&gt; Foo{#2574}
  // ... including omitting parens for constructor arguments as optional 
  new Foo;    // =&gt; Foo{#2577}
  
  // passing class name in a string (mentioned in manual) however fails
  new &quot;Foo&quot;;
  new &quot;Foo()&quot;;
  new &quot;Foo&quot;();
  // =&gt; PHP Parse error: Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
  
  // passing class name in a string works only indirectly, through a variable (why?)
  $className = &quot;Foo&quot;;
  new $className;    // Foo {#2580}
  
  // other expressions resulting in *string* value also does not seem to work
  function getFoo() {return &quot;Foo&quot;;}
  new (getFoo());
  // =&gt; PHP Error:  syntax error, unexpected '(', expecting ';'
  </code></pre>
  <p>What all possible syntax for <code>new</code> is allowed?
  Is there some syntax reference for PHP, where this and other core language constructs are described in detail? Like The Python Language Reference?</p>