src/parser/expr.js
function() {
    const result = this.node("new");
    this.expect(this.tok.T_NEW) && this.next();
    let args = [];
    if (this.token === this.tok.T_CLASS) {
      const what = this.node("class");
      // Annonymous class declaration
      let propExtends = null,
        propImplements = null,
        body = null;
      if (this.next().token === "(") {
        args = this.read_function_argument_list();
      }
      if (this.token == this.tok.T_EXTENDS) {
        propExtends = this.next().read_namespace_name();
      }
      if (this.token == this.tok.T_IMPLEMENTS) {
        propImplements = this.next().read_name_list();
      }
      if (this.expect("{")) {
        body = this.next().read_class_body();
      }
      return result(
        what(null, propExtends, propImplements, body, [0, 0, 0]),
        args
      );
    }
    // Already existing class
    const name = this.read_new_class_name();
    if (this.token === "(") {
      args = this.read_function_argument_list();
    }
    return result(name, args);
  }
function() {
    const result = this.node("new");
    this.expect(this.tok.T_NEW) && this.next();
    let args = [];
    if (this.token === this.tok.T_CLASS) {
      const what = this.node("class");
      // Annonymous class declaration
      let propExtends = null,
        propImplements = null,
        body = null;
      if (this.next().token === "(") {
        args = this.read_function_argument_list();
      }
      if (this.token == this.tok.T_EXTENDS) {
        propExtends = this.next().read_namespace_name();
      }
      if (this.token == this.tok.T_IMPLEMENTS) {
        propImplements = this.next().read_name_list();
      }
      if (this.expect("{")) {
        body = this.next().read_class_body();
      }
      return result(
        what(null, propExtends, propImplements, body, [0, 0, 0]),
        args
      );
    }
    // Already existing class
    const name = this.read_new_class_name();
    if (this.token === "(") {
      args = this.read_function_argument_list();
    }
    return result(name, args);
  }
function ( ) { const result = this . node ( "new" ) ; this . expect ( this . tok . T_NEW ) && this . next ( ) ; let args = [ ] ; if ( this . token === this . tok . T_CLASS ) { const what = this . node ( "class" ) ; // Annonymous class declaration let propExtends = null , propImplements = null , body = null ; if ( this . next ( ) . token === "(" ) { args = this . read_function_argument_list ( ) ; } if ( this . token == this . tok . T_EXTENDS ) { propExtends = this . next ( ) . read_namespace_name ( ) ; } if ( this . token == this . tok . T_IMPLEMENTS ) { propImplements = this . next ( ) . read_name_list ( ) ; } if ( this . expect ( "{" ) ) { body = this . next ( ) . read_class_body ( ) ; } return result ( what ( null , propExtends , propImplements , body , [ 0 , 0 , 0 ] ) , args ) ; } // Already existing class const name = this . read_new_class_name ( ) ; if ( this . token === "(" ) { args = this . read_function_argument_list ( ) ; } return result ( name , args ) ; }
```ebnf
new_expr ::= T_NEW (namespace_name function_argument_list) | (T_CLASS ... class declaration)
```
https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L850
ebnf new_expr :: = T_NEW ( namespace_name function_argument_list ) | ( T_CLASS ... class declaration ) https : // github . com / php / php - src / blob / master / Zend / zend_language_parser . y#L850