ReflectionClass::getInterfaceNames

(PHP 5 >= 5.2.0)

ReflectionClass::getInterfaceNamesGets the interface names

Description

public array ReflectionClass::getInterfaceNames ( void )

Get the interface names.

Parameters

This function has no parameters.

Return Values

A numerical array with interface names as the values.

Examples

Example #1 ReflectionClass::getInterfaceNames() example

<?php
interface Foo { }

interface 
Bar { }

class 
Baz implements FooBar { }

$rc1 = new ReflectionClass("Baz");

print_r($rc1->getInterfaceNames());
?>

The above example will output something similar to:

Array
(
    [0] => Foo
    [1] => Bar
)

See Also

Коментарии

Автор:
It seems the interface names are actually listed in a defined order:
- "extends" takes precedence over "implements" (i.e. first will be interfaces from (implemented in) the parent class (if any), then interfaces implemented in the class itself)
- when multiple interfaces are implemented at one time/level, it can be:
+ from an "implements" : they're listed in the defined order
+ from an "extends" (a class extends another class which implements multiple interfaces; or an interface extends multiple interfaces) : they're listed in REVERSE order

<?php
interface Foo {}
interface 
Bar {}
interface 
Other {}
interface 
Foobar extends FooBar {}
interface 
Barfoo extends BarFoo {}

class 
Test1 implements FooBar {}
class 
Test2 implements BarFoo {}

class 
Test3 extends Test1 {}
class 
Test4 extends Test2 {}

class 
Test5 extends Test1 implements Other {}

class 
Test6 implements FoobarOther {}
class 
TestO implements Other {}
class 
Test7 extends TestO implements Barfoo {}

$r=new ReflectionClass('Test1');
print_r($r->getInterfaceNames()); // Foo, Bar

$r=new ReflectionClass('Test2');
print_r($r->getInterfaceNames()); // Bar, Foo

$r=new ReflectionClass('Test3');
print_r($r->getInterfaceNames()); // Bar, Foo

$r=new ReflectionClass('Test4');
print_r($r->getInterfaceNames()); // Foo, Bar

$r=new ReflectionClass('Test5');
print_r($r->getInterfaceNames()); // Bar, Foo, Other

$r=new ReflectionClass('Test6');
print_r($r->getInterfaceNames()); // Foobar, Bar, Foo, Other

$r=new ReflectionClass('Test7');
print_r($r->getInterfaceNames()); // Other, Barfoo, Foo, Bar
?>
2011-03-27 07:11:33
http://php5.kiev.ua/manual/ru/reflectionclass.getinterfacenames.html
Автор:
For the record, it will return the full name (not the short name) for each Interface

Example with namespace would've helped.
2020-07-23 15:43:40
http://php5.kiev.ua/manual/ru/reflectionclass.getinterfacenames.html

    Поддержать сайт на родительском проекте КГБ