Skip to content

Instantly share code, notes, and snippets.

@suin
Created November 20, 2011 07:33
Show Gist options
  • Save suin/1379930 to your computer and use it in GitHub Desktop.
Save suin/1379930 to your computer and use it in GitHub Desktop.
[PHP] ReflectionClassで親クラスのクラス名を取得してみる ref: http://qiita.com/items/1106
<?php
class Foo
{
}
class Bar extends Foo
{
}
class Baz extends Bar
{
}
$fooClass = new ReflectionClass('Foo');
var_dump($fooClass->getParentClass());
// bool(false)
$barClass = new ReflectionClass('Bar');
var_dump($barClass->getParentClass());
/*
object(ReflectionClass)#3 (1) {
["name"]=>
string(3) "Foo"
}
*/
$bazClass = new ReflectionClass('Baz');
var_dump($bazClass->getParentClass());
/*
object(ReflectionClass)#4 (1) {
["name"]=>
string(3) "Bar"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment