[php 8.4] MyClass()->method() 를 이제 괄호없이 사용 가능해요 > 영카트5 팁자료실

영카트5 팁자료실

[php 8.4] MyClass()->method() 를 이제 괄호없이 사용 가능해요 정보

[php 8.4] MyClass()->method() 를 이제 괄호없이 사용 가능해요

본문

 


// 괄호를 사용한 기존 방식 
$request = (new Request())->withMethod('GET')->withUri('/hello-world'); 
// PHP Parse error (<= PHP 8.3): syntax error, unexpected token "->" 
$request = new Request()->withMethod('GET')->withUri('/hello-world');

 

8.4 부터 아래와 같은 표현이 가능합니다.


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"
);

 

참고(영문): https://laravel-news.com/php-8-4-class-instantiation-without-extra-parenthesis 

추천
2
  • 복사

댓글 3개

© SIRSOFT
현재 페이지 제일 처음으로