[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 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 311 |
투명한열정
|
5년 전 | 2846 | |
| 310 |
|
5년 전 | 6386 | |
| 309 |
|
5년 전 | 3347 | |
| 308 |
|
5년 전 | 3779 | |
| 307 |
|
5년 전 | 3202 | |
| 306 |
|
5년 전 | 2878 | |
| 305 | 5년 전 | 4505 | ||
| 304 | 5년 전 | 5986 | ||
| 303 | 5년 전 | 5185 | ||
| 302 | 5년 전 | 2309 | ||
| 301 | 5년 전 | 3598 | ||
| 300 | 5년 전 | 2489 | ||
| 299 | 5년 전 | 2148 | ||
| 298 |
|
5년 전 | 1974 | |
| 297 |
sozet
|
5년 전 | 2276 | |
| 296 |
sozet
|
5년 전 | 2437 | |
| 295 |
sozet
|
5년 전 | 4634 | |
| 294 |
sozet
|
5년 전 | 2650 | |
| 293 |
|
5년 전 | 2822 | |
| 292 | 5년 전 | 2027 | ||
| 291 | 5년 전 | 6669 | ||
| 290 | 5년 전 | 2637 | ||
| 289 |
퍼스트가든
|
5년 전 | 2667 | |
| 288 | 5년 전 | 3002 | ||
| 287 | 5년 전 | 2670 | ||
| 286 |
사노라가노라
|
5년 전 | 2698 | |
| 285 |
사노라가노라
|
5년 전 | 2072 | |
| 284 | 6년 전 | 4791 | ||
| 283 |
v푸른하늘v
|
6년 전 | 3868 | |
| 282 |
|
6년 전 | 4162 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기