[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 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 401 |
|
1년 전 | 2341 | |
| 400 |
|
1년 전 | 1392 | |
| 399 | 1년 전 | 2779 | ||
| 398 | 1년 전 | 874 | ||
| 397 |
|
1년 전 | 2750 | |
| 396 | 1년 전 | 1340 | ||
| 395 | 1년 전 | 738 | ||
| 394 | 1년 전 | 457 | ||
| 393 | 1년 전 | 1014 | ||
| 392 |
다케미카코
|
1년 전 | 2658 | |
| 391 |
|
1년 전 | 808 | |
| 390 |
사노라가노라
|
1년 전 | 1053 | |
| 389 | 1년 전 | 505 | ||
| 388 |
|
1년 전 | 85437 | |
| 387 | 1년 전 | 824 | ||
| 386 | 2년 전 | 2521 | ||
| 385 | 2년 전 | 831 | ||
| 384 | 2년 전 | 1850 | ||
| 383 |
|
2년 전 | 1876 | |
| 382 | 2년 전 | 1429 | ||
| 381 | 2년 전 | 2582 | ||
| 380 |
|
2년 전 | 2131 | |
| 379 |
e4uhack
|
2년 전 | 2075 | |
| 378 |
|
2년 전 | 1067 | |
| 377 |
|
2년 전 | 1383 | |
| 376 | 2년 전 | 1215 | ||
| 375 |
|
2년 전 | 2237 | |
| 374 |
페이투페이
|
2년 전 | 1731 | |
| 373 |
|
2년 전 | 1456 | |
| 372 | 2년 전 | 1238 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기