라이브러리

[PHP] get_declared_interfaces - 선언된 모든 인터페이스의 배열을 반환합니다.




PHP에서 get_declared_interfaces


`get_declared_interfaces`는 PHP에서 인터페이스를 선언한 목록을 반환하는 내장 함수입니다. 이 함수는 PHP 7.2.0 버전부터 사용할 수 있습니다.

# 인터페이스 선언


인터페이스는 클래스와 유사하지만, 클래스가 구현해야 하는 메서드 목록을 정의하는 추상적인 개념입니다. 인터페이스는 클래스가 구현해야 하는 메서드 목록을 정의하고, 클래스는 인터페이스를 implements 키워드를 사용하여 구현합니다.

# get_declared_interfaces 예제


다음 예제에서는 `get_declared_interfaces` 함수를 사용하여 인터페이스를 선언한 목록을 반환하는 방법을 보여줍니다.

#hostingforum.kr
php

// 인터페이스 선언

interface Animal {

    public function sound();

}



interface Mammal {

    public function eat();

}



// 인터페이스 선언

interface Bird extends Animal {

    public function fly();

}



// 인터페이스 선언

class Dog implements Animal, Mammal {

    public function sound() {

        echo "Woof!
";

    }



    public function eat() {

        echo "Dog is eating.
";

    }

}



// 인터페이스 선언

class Cat implements Animal, Mammal {

    public function sound() {

        echo "Meow!
";

    }



    public function eat() {

        echo "Cat is eating.
";

    }

}



// get_declared_interfaces 함수 사용

$interfaces = get_declared_interfaces();



// 인터페이스 목록 출력

foreach ($interfaces as $interface) {

    echo $interface . "
";

}



# 결과


위 예제를 실행하면 다음 결과가 출력됩니다.

#hostingforum.kr


Animal

Mammal

Bird

Dog

Cat



# get_declared_interfaces 함수 사용 방법


`get_declared_interfaces` 함수는 다음과 같은 방법으로 사용할 수 있습니다.

* 인터페이스 목록을 반환하는 데 사용할 수 있습니다.
* 인터페이스를 선언한 목록을 확인하는 데 사용할 수 있습니다.

# 참고


* `get_declared_interfaces` 함수는 PHP 7.2.0 버전부터 사용할 수 있습니다.
* 인터페이스는 클래스와 유사하지만, 클래스가 구현해야 하는 메서드 목록을 정의하는 추상적인 개념입니다.
* 인터페이스는 클래스가 구현해야 하는 메서드 목록을 정의하고, 클래스는 인터페이스를 implements 키워드를 사용하여 구현합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 529 페이지

검색

게시물 검색