<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="解决PHP is_subclass_of函数的BUG：Inconsistent behavior of is_subclass_of with interfaces" id="card1">
<p> 游客</p><p>
标题:解决PHP is_subclass_of函数的BUG：Inconsistent behavior of is_subclass_of with interfaces<br/>
正文:<br/>
is_subclass_of的作用：代码如下:bool is_subclass_of ( object object, string class_name )如果对象 object 所属类是类 class_name 的子类，则返回 TRUE，否则返回 FALSE。注: 自 PHP 5.0.3 起也可以用一个字符串来指定 object 参数（类名）。使用例子：代码如下:#判断$className是否是$type的子类is_subclass_of($className,$type);php5.3.7版本前针对interface会有一个bugbug:https://bugs.php.net/bug.php?id=53727代码如下:interface MyInterface {}class ParentClass implements MyInterface { }class ChildClass extends ParentClass { }# trueis_subclass_of('ChildClass', 'MyInterface');# falseis_subclass_of('ParentClass', 'MyInterface');解决办法：代码如下:function isSubclassOf($className, $type){    // 如果 $className 所属类是 $type 的子类，则返回 TRUE       if (is_subclass_of($className, $type)) {        return true;    }    // 如果php版本&amp;gt;=5.3.7 不存在interface bug 所以 $className 不是 $type 的子类    if (version_compare(PHP_VERSION, '5.3.7', '&amp;gt;=')) {        return false;&amp;nbsp<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1764&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1764&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1764&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1764&amp;Page=2">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=1764">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=1764">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>