[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개
1년 전
감사 합니다.
1년 전
오! 많이 발전 됐군요 좋은 지식 감사합니다
JanetNelson
1년 전
감사 합니다.
게시판 목록
영카트5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 101 | 10년 전 | 5225 | ||
| 100 | 10년 전 | 5109 | ||
| 99 | 10년 전 | 5396 | ||
| 98 | 10년 전 | 6735 | ||
| 97 |
|
10년 전 | 5434 | |
| 96 | 10년 전 | 3236 | ||
| 95 |
맥콜맛치킨
|
10년 전 | 2901 | |
| 94 | 10년 전 | 6720 | ||
| 93 | 10년 전 | 7943 | ||
| 92 |
RedDJ
|
10년 전 | 6287 | |
| 91 | 10년 전 | 4780 | ||
| 90 | 10년 전 | 6766 | ||
| 89 | 10년 전 | 9941 | ||
| 88 |
|
10년 전 | 5874 | |
| 87 | 10년 전 | 5461 | ||
| 86 |
RedDJ
|
10년 전 | 4455 | |
| 85 | 10년 전 | 5455 | ||
| 84 |
꼬리가보여
|
10년 전 | 7677 | |
| 83 | 10년 전 | 5152 | ||
| 82 | 10년 전 | 6385 | ||
| 81 | 10년 전 | 5686 | ||
| 80 | 10년 전 | 9739 | ||
| 79 |
|
10년 전 | 6588 | |
| 78 | 10년 전 | 15026 | ||
| 77 | 10년 전 | 5693 | ||
| 76 | 10년 전 | 5612 | ||
| 75 | 10년 전 | 8474 | ||
| 74 | 10년 전 | 11520 | ||
| 73 | 10년 전 | 5185 | ||
| 72 | 10년 전 | 11554 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기