本文整理匯總了PHP中XPClass::isInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP XPClass::isInstance方法的具體用法?PHP XPClass::isInstance怎麽用?PHP XPClass::isInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類XPClass
的用法示例。
在下文中一共展示了XPClass::isInstance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: valuesOf
/**
* Returns the enumeration members for a given class
*
* @param lang.XPClass class class object
* @return lang.Enum[]
* @throws lang.IllegalArgumentException in case the given class is not an enum
*/
public static function valuesOf(XPClass $class)
{
if (!$class->isEnum()) {
throw new IllegalArgumentException('Argument class must be lang.XPClass<? extends lang.Enum>');
}
$r = [];
foreach ($class->reflect()->getStaticProperties() as $prop) {
$class->isInstance($prop) && ($r[] = $prop);
}
return $r;
}
示例2: valuesOf
/**
* Returns the enumeration members for a given class
*
* @param lang.XPClass class class object
* @return self[]
* @throws lang.IllegalArgumentException in case the given class is not an enum
*/
public static function valuesOf(XPClass $class)
{
if (!$class->isEnum()) {
throw new IllegalArgumentException('Argument class must be lang.XPClass<? extends lang.Enum>');
}
$r = [];
if ($class->isSubclassOf(self::class)) {
foreach ($class->reflect()->getStaticProperties() as $prop) {
$class->isInstance($prop) && ($r[] = $prop);
}
} else {
$t = ClassLoader::defineClass($class->getName() . 'Enum', self::class, []);
foreach ($class->reflect()->getMethod('getValues')->invoke(null) as $name => $ordinal) {
$r[] = $t->newInstance($ordinal, $name);
}
}
return $r;
}