PHP 8.3

// 괄호 없으면 PHP Parse error:

$request = (new Request())->withMethod('GET')->withUri('/hello-world');  

 

 

 

PHP 8.4

$request = new Request()->withMethod('GET')->withUri('/hello-world');

 

 

RFC 통과 각.

 

해당 RFC  통과로 가능해지는것들

 

쉽게 알기위해 var_dump 로 덤프뜰때를 표현하면

 

$myClass = MyClass::class;
var_dump(
    new $myClass()::CONSTANT,        // string(8)  "constant"
    new $myClass()::$staticProperty, // string(14) "staticProperty"
    new $myClass()::staticMethod(),  // string(12) "staticMethod"
    new $myClass()->property,        // string(8)  "property"
    new $myClass()->method(),        // string(6)  "method"
    new $myClass()(),                // string(8)  "__invoke"
);

 

중간변수 필요하지 않을때는 이렇게 바로바로 할 수 있다는군요

  • Lv9
    개념 상으로는 괄호가 있는 것이 낫겠습니다만... 보기에는 없는 편이 낫겠군요.
  • Lv9 ? Lv3
    RFC 제안서 제출자가 적어놓길 다른언어들은 괄호가 없다네요
    불편하다던...