forked from zendframework/zendframework
/
SubClass.php
47 lines (43 loc) · 1.16 KB
/
SubClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/
namespace Zend\Stdlib;
use ReflectionClass;
/**
* @see https://bugs.php.net/bug.php?id=53727
*
* @category Zend
* @package Zend_Stdlib
* @subpackage SubClass
*/
abstract class SubClass
{
/**
* Checks if the object has this class as one of its parents
*
* @see https://bugs.php.net/bug.php?id=53727
*
* @param string $className
* @param string $type
*/
public static function isSubclassOf($className, $type)
{
if (version_compare(PHP_VERSION, '5.3.7', '>=')) {
return is_subclass_of($className, $type);
}
if (is_subclass_of($className, $type)) {
return true;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);
return $r->implementsInterface($type);
}
}