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

 

[code]

// 괄호를 사용한 기존 방식 
$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');
[/code]

 

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

[code]

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"

);

[/code]

 

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

|

댓글 3개

감사 합니다.

오! 많이 발전 됐군요 좋은 지식 감사합니다

댓글을 작성하시려면 로그인이 필요합니다.

영카트5 팁자료실

+
제목 글쓴이 날짜 조회
9개월 전 조회 1,109
9개월 전 조회 802
11개월 전 조회 1,407
11개월 전 조회 1,054
11개월 전 조회 1,016
1년 전 조회 1,414
1년 전 조회 1,595
1년 전 조회 1,030
1년 전 조회 1,785
1년 전 조회 1,245
1년 전 조회 1,347
1년 전 조회 2,884
1년 전 조회 1,954
1년 전 조회 3,379
1년 전 조회 1,269
1년 전 조회 3,637
1년 전 조회 1,777
1년 전 조회 1,139
1년 전 조회 827
1년 전 조회 1,371
1년 전 조회 3,099
2년 전 조회 1,159
2년 전 조회 1,445
2년 전 조회 870
2년 전 조회 8.6만
2년 전 조회 1,213
2년 전 조회 2,927
2년 전 조회 1,163
2년 전 조회 2,251
2년 전 조회 2,286