<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Return the parent classes of the given class</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.class-implements.html">class_implements</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.class-uses.html">class_uses</a></div> <div class="up"><a href="ref.spl.html">SPL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.class-parents" class="refentry"> <div class="refnamediv"> <h1 class="refname">class_parents</h1> <p class="verinfo">(PHP 5 >= 5.1.0)</p><p class="refpurpose"><span class="refname">class_parents</span> — <span class="dc-title"> Return the parent classes of the given class </span></p> </div> <div class="refsect1 description" id="refsect1-function.class-parents-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>class_parents</strong></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$class</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$autoload</code><span class="initializer"> = true</span></span> ] )</div> <p class="para rdfs-comment"> This function returns an array with the name of the parent classes of the given <em><code class="parameter">class</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.class-parents-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">class</code></em></span> <dd> <p class="para"> An object (class instance) or a string (class name). </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">autoload</code></em></span> <dd> <p class="para"> Whether to allow this function to load the class automatically through the <span class="function"><a href="function.autoload.html" class="function">__autoload()</a></span> magic method. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.class-parents-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> An array on success, or <strong><code>FALSE</code></strong> on error. </p> </div> <div class="refsect1 changelog" id="refsect1-function.class-parents-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.1.0</td> <td> Added the option to pass the <em><code class="parameter">class</code></em> parameter as a string. Added the <em><code class="parameter">autoload</code></em> parameter. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.class-parents-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3913"> <p><strong>Example #1 <span class="function"><strong>class_parents()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">foo </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">bar </span><span style="color: #007700">extends </span><span style="color: #0000BB">foo </span><span style="color: #007700">{}<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_parents</span><span style="color: #007700">(new </span><span style="color: #0000BB">bar</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// since PHP 5.1.0 you may also specify the parameter as a string<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_parents</span><span style="color: #007700">(</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">));<br /><br /><br />function </span><span style="color: #0000BB">__autoload</span><span style="color: #007700">(</span><span style="color: #0000BB">$class_name</span><span style="color: #007700">) {<br /> require_once </span><span style="color: #0000BB">$class_name </span><span style="color: #007700">. </span><span style="color: #DD0000">'.php'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// use __autoload to load the 'not_loaded' class<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_parents</span><span style="color: #007700">(</span><span style="color: #DD0000">'not_loaded'</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Array ( [foo] => foo ) Array ( [parent_of_not_loaded] => parent_of_not_loaded ) </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.class-parents-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.class-implements.html" class="function" rel="rdfs-seeAlso">class_implements()</a> - Return the interfaces which are implemented by the given class</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.class-implements.html">class_implements</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.class-uses.html">class_uses</a></div> <div class="up"><a href="ref.spl.html">SPL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>