正文开始 <p>http://www.cnblogs.com/longzhongren/p/5852182.html</p><p></p><p>如果对象 object所属类是类 class_name的子类,则返回 TRUE ,否则返回 FALSE 。</p><p>例子:</p><br /><p>// define a class<br /> class WidgetFactory<br /> {<br /> var $oink = 'moo' ;<br />}<br /> <br />// define a child class<br /> class WidgetFactory_Child extends WidgetFactory<br /> {<br /> var $oink = 'oink' ;<br />}<br /> <br />// create a new object<br /> $WF = new WidgetFactory ();<br /> $WFC = new WidgetFactory_Child ();<br /> <br />if ( is_subclass_of ( $WFC , 'WidgetFactory' )) {<br /> echo "yes, WFC is a subclass of WidgetFactoryn" ;<br />} else {<br /> echo "no, WFC is not a subclass of WidgetFactoryn" ;<br />}<br /> <br /><br />if ( is_subclass_of ( $WF , 'WidgetFactory' )) {<br /> echo "yes, WF is a subclass of WidgetFactoryn" ;<br />} else {<br /> echo "no, WF is not a subclass of WidgetFactoryn" ;<br />}<br /> <br /><br />// usable only since PHP 5.0.3<br /> if ( is_subclass_of ( 'WidgetFactory_Child' , 'WidgetFactory' )) {<br /> echo "yes, WidgetFactory_Child is a subclass of WidgetFactoryn" ;<br />} else {<br /> echo "no, WidgetFactory_Child is not a subclass of WidgetFactoryn" ;<br />}</p><p><br /></p><p><br /></p><p></p><p>运行结果:</p>yes, WFC is a subclass of WidgetFactory
no, WF is not a subclass of WidgetFactory
yes, WidgetFactory_Child is a subclass of WidgetFactory<br />
正文结束 |
PHP接口(interface)和抽象类(abstract) | php中 instanceof有什么用 |