Late Static Binding (LSB):메서드 내부에서 현재 클래스의 정적 메서드 또는 프로퍼티를 호출할 때 사용
Author
siwon
Date
2023-10-24 16:24
Views
1000
Late Static Binding (LSB)는 PHP에서 객체 지향 프로그래밍에서 사용되는 개념 중 하나입니다. 이것은 객체 지향 상속과 메서드 오버라이딩과 관련이 있습니다. LSB는 상위 클래스(부모 클래스)의 정적 메서드 내에서 서브 클래스(자식 클래스)의 정적 메서드 또는 프로퍼티를 호출하는 방법을 제공합니다.
이 개념은 주로 `static` 키워드를 사용하여 구현됩니다. 정적 메서드 또는 프로퍼티에 대한 상위 클래스와 서브 클래스 간의 차이를 해소하기 위해 사용됩니다.
LSB를 사용하기 위해 `static::` 키워드를 사용합니다. 이것은 메서드 내부에서 현재 클래스의 정적 메서드 또는 프로퍼티를 호출할 때 사용됩니다. 다음은 LSB의 간단한 예제입니다:
```php
class ParentClass {
public static function whoAmI() {
echo 'I am the parent class.';
}
public static function callWhoAmI() {
static::whoAmI();
}
}
class ChildClass extends ParentClass {
public static function whoAmI() {
echo 'I am the child class.';
}
}
ChildClass::callWhoAmI(); // 출력: I am the child class.
```
여기서 `ParentClass`의 `callWhoAmI` 메서드 내에서 `static::whoAmI()`를 호출하면, 실제 호출될 메서드는 호출 시점의 클래스에 따라 달라집니다. 따라서 `ChildClass`에서 호출하면 `I am the child class.`가 출력됩니다.
Late Static Binding은 다중 레벨의 클래스 계층 구조에서 상위 클래스와 서브 클래스 간의 메서드 호출 동작을 조절하는 데 유용합니다.
Total 0
You must be logged in to post a comment.
Total 45
Number | Title | Author | Date | Votes | Views |
40 |
php formatter
siwon
|
2024.11.26
|
Votes -1
|
Views 819
|
siwon | 2024.11.26 | -1 | 819 |
39 |
html center 중앙정렬 tailwind
siwon
|
2024.07.27
|
Votes 0
|
Views 1139
|
siwon | 2024.07.27 | 0 | 1139 |
38 |
dropdown menu alpinejs 사용 버전
siwon
|
2024.04.30
|
Votes 0
|
Views 1158
|
siwon | 2024.04.30 | 0 | 1158 |
37 |
dropdown menu 간단 버전
siwon
|
2024.04.30
|
Votes 0
|
Views 1103
|
siwon | 2024.04.30 | 0 | 1103 |
36 |
The Standard PHP Library (SPL) is a collection of classes and interfaces that provide core functionality to PHP developers.
siwon
|
2023.10.24
|
Votes 0
|
Views 1689
|
siwon | 2023.10.24 | 0 | 1689 |
35 |
session 과 쿠키
siwon
|
2023.10.24
|
Votes 0
|
Views 1072
|
siwon | 2023.10.24 | 0 | 1072 |
34 |
Late Static Binding (LSB):메서드 내부에서 현재 클래스의 정적 메서드 또는 프로퍼티를 호출할 때 사용
siwon
|
2023.10.24
|
Votes 0
|
Views 1000
|
siwon | 2023.10.24 | 0 | 1000 |
33 |
PHP 예외 처리(Exception Handling)
siwon
|
2023.10.10
|
Votes 0
|
Views 1270
|
siwon | 2023.10.10 | 0 | 1270 |
32 |
php exception
siwon
|
2023.10.10
|
Votes 0
|
Views 1492
|
siwon | 2023.10.10 | 0 | 1492 |
31 |
예외(Exception)를 처리하기 위해 try...catch 블록을 사용하는 방법
siwon
|
2023.10.10
|
Votes 0
|
Views 1063
|
siwon | 2023.10.10 | 0 | 1063 |
30 |
Preserving Parent Class Functionality in overriding
siwon
|
2023.09.26
|
Votes 0
|
Views 884
|
siwon | 2023.09.26 | 0 | 884 |
29 |
oop 세부항목
siwon
|
2023.09.26
|
Votes 0
|
Views 889
|
siwon | 2023.09.26 | 0 | 889 |
28 |
method chaining
siwon
|
2023.09.25
|
Votes 0
|
Views 1098
|
siwon | 2023.09.25 | 0 | 1098 |
27 |
interface implements
siwon
|
2023.09.19
|
Votes 0
|
Views 942
|
siwon | 2023.09.19 | 0 | 942 |
![]()
siwon
|
2023.10.24
|
Votes 0
|
Views 787
|
siwon | 2023.10.24 | 0 | 787 | |
26 |
abstract class : 부모 class로 사용되며 자식(extends 한)에게 abstract method를 강제함(그들만의 방식으로)
siwon
|
2023.09.19
|
Votes 0
|
Views 880
|
siwon | 2023.09.19 | 0 | 880 |
25 |
isset() / unset()
siwon
|
2023.09.18
|
Votes 0
|
Views 991
|
siwon | 2023.09.18 | 0 | 991 |
24 |
magic methods-어떤 상황이 되면 call 하지 않아도 자동으로 실행되는 메소드
siwon
|
2023.09.18
|
Votes 0
|
Views 1001
|
siwon | 2023.09.18 | 0 | 1001 |
23 |
MD(markdown) file
siwon
|
2023.09.12
|
Votes 0
|
Views 952
|
siwon | 2023.09.12 | 0 | 952 |
22 |
usort
siwon
|
2023.08.30
|
Votes 0
|
Views 897
|
siwon | 2023.08.30 | 0 | 897 |
21 |
closure=unanimous function
siwon
|
2023.08.30
|
Votes 0
|
Views 1000
|
siwon | 2023.08.30 | 0 | 1000 |
![]()
siwon
|
2023.10.24
|
Votes 0
|
Views 1779
|
siwon | 2023.10.24 | 0 | 1779 | |
20 |
reference variable &
siwon
|
2023.08.29
|
Votes 0
|
Views 982
|
siwon | 2023.08.29 | 0 | 982 |
![]()
siwon
|
2023.08.30
|
Votes 0
|
Views 968
|
siwon | 2023.08.30 | 0 | 968 | |
19 |
PHP 변수 : 스칼라(Scalar), 복합(Composite), 그리고 리소스(Resource)
siwon
|
2023.08.22
|
Votes 0
|
Views 1055
|
siwon | 2023.08.22 | 0 | 1055 |
18 |
if : vs {}
siwon
|
2023.08.22
|
Votes 0
|
Views 851
|
siwon | 2023.08.22 | 0 | 851 |
17 |
null coalescing operator
siwon
|
2023.08.18
|
Votes 0
|
Views 1133
|
siwon | 2023.08.18 | 0 | 1133 |
16 |
arrary functions
siwon
|
2023.08.18
|
Votes 0
|
Views 938
|
siwon | 2023.08.18 | 0 | 938 |