<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://htyp.org/mw/index.php?action=history&amp;feed=atom&amp;title=PHP%2Finheritance%2Fcode</id>
	<title>PHP/inheritance/code - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://htyp.org/mw/index.php?action=history&amp;feed=atom&amp;title=PHP%2Finheritance%2Fcode"/>
	<link rel="alternate" type="text/html" href="https://htyp.org/mw/index.php?title=PHP/inheritance/code&amp;action=history"/>
	<updated>2026-08-12T19:46:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://htyp.org/mw/index.php?title=PHP/inheritance/code&amp;diff=28897&amp;oldid=prev</id>
		<title>Woozle: Created page with &quot;&lt;syntaxhighlight lang=php&gt; &lt;?php /**  * PURPOSE: The idea is to produce a handy reference-matrix of what the various class-inheritance functions/operators report  *  under var...&quot;</title>
		<link rel="alternate" type="text/html" href="https://htyp.org/mw/index.php?title=PHP/inheritance/code&amp;diff=28897&amp;oldid=prev"/>
		<updated>2024-04-05T13:26:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;syntaxhighlight lang=php&amp;gt; &amp;lt;?php /**  * PURPOSE: The idea is to produce a handy reference-matrix of what the various class-inheritance functions/operators report  *  under var...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * PURPOSE: The idea is to produce a handy reference-matrix of what the various class-inheritance functions/operators report&lt;br /&gt;
 *  under various conditions.&lt;br /&gt;
 *  * vertical axis: two entities being compared&lt;br /&gt;
 *  * horizontal axis: instanceof, is_a(,,FALSE), is_a(,,TRUE), is_subclass_of(,,FALSE), is_subclass_of(,,TRUE)&lt;br /&gt;
 * HISTORY:&lt;br /&gt;
 *  2024-04-04 created because the documentation is maddeningly unclear on some key points and doesn&amp;#039;t mention others at all&lt;br /&gt;
 *  2024-04-05 more or less finalized&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// PLAINTEXT&lt;br /&gt;
/*&lt;br /&gt;
define(&amp;#039;CRLF&amp;#039;,&amp;quot;\n&amp;quot;);&lt;br /&gt;
define(&amp;#039;TABLE_OPEN&amp;#039;,&amp;#039;&amp;#039;);&lt;br /&gt;
define(&amp;#039;TABLE_SHUT&amp;#039;,&amp;#039;&amp;#039;);&lt;br /&gt;
define(&amp;#039;ROW_OPEN&amp;#039;,&amp;#039;&amp;#039;);&lt;br /&gt;
define(&amp;#039;ROW_SHUT&amp;#039;,&amp;quot;\n&amp;quot;);&lt;br /&gt;
define(&amp;#039;CELL_OPEN&amp;#039;,&amp;#039; &amp;#039;);&lt;br /&gt;
define(&amp;#039;CELL_SHUT&amp;#039;,&amp;#039; &amp;#039;);&lt;br /&gt;
&lt;br /&gt;
function Cell(string $s) : string { return CELL_OPEN.str_pad($s,8,&amp;#039; &amp;#039;).CELL_SHUT; }&lt;br /&gt;
function WholeRow(string $s) : string { return ROW_OPEN.CELL_OPEN.$s.CELL_SHUT.ROW_SHUT; }&lt;br /&gt;
*/&lt;br /&gt;
// HTML&lt;br /&gt;
&lt;br /&gt;
// to be written&lt;br /&gt;
&lt;br /&gt;
// WIKITEXT&lt;br /&gt;
&lt;br /&gt;
define(&amp;#039;CRLF&amp;#039;,&amp;quot;\n&amp;quot;);&lt;br /&gt;
define(&amp;#039;TABLE_OPEN&amp;#039;,&amp;quot;{| class=&amp;#039;wikitable sortable&amp;#039;\n! arguments || B instanceof A || is_a(B,A,FALSE) || is_a(B,A,TRUE) || is_subclass_of(B,A,FALSE) || is_subclass_of(B,A,TRUE) \n&amp;quot;);&lt;br /&gt;
define(&amp;#039;TABLE_SHUT&amp;#039;,&amp;quot;|}\n&amp;quot;);&lt;br /&gt;
define(&amp;#039;ROW_OPEN&amp;#039;,&amp;quot;|-\n&amp;quot;);&lt;br /&gt;
define(&amp;#039;ROW_SHUT&amp;#039;,&amp;quot;&amp;quot;);&lt;br /&gt;
define(&amp;#039;CELL_OPEN&amp;#039;,&amp;quot;| &amp;quot;);&lt;br /&gt;
define(&amp;#039;CELL_SHUT&amp;#039;,&amp;quot;\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
function Cell(string $s) : string { return CELL_OPEN.$s.CELL_SHUT; }&lt;br /&gt;
function WholeRow(string $s) : string { return ROW_OPEN.CELL_OPEN.&amp;quot;colspan=6 | $s&amp;quot;.CELL_SHUT.ROW_SHUT; }&lt;br /&gt;
&lt;br /&gt;
// ----&lt;br /&gt;
&lt;br /&gt;
interface iA {}&lt;br /&gt;
interface iB extends iA {}            // interface B inherits from interface A&lt;br /&gt;
trait tA {}&lt;br /&gt;
class cA implements iA { use tA; }    // class A inherits from iA and tA&lt;br /&gt;
$oA = new cA;                         // object of class A&lt;br /&gt;
class cB extends cA implements iB {}  // class B inherits from cA and iB&lt;br /&gt;
$oB = new cB;                         // object of class B&lt;br /&gt;
class cD {}                           // unrelated class&lt;br /&gt;
$oD = new cD;                         // object of class D&lt;br /&gt;
&lt;br /&gt;
function YesNo(bool $b) : string { return $b ? &amp;#039;Y&amp;#039; : &amp;#039;-&amp;#039;; }&lt;br /&gt;
&lt;br /&gt;
function RenderRow(string $sDesc,$v1,string $v2) : string {&lt;br /&gt;
    $s1 = YesNo( $v1 instanceof $v2 );&lt;br /&gt;
    $s2 = YesNo( is_a($v1,$v2,FALSE) );&lt;br /&gt;
    $s3 = YesNo( is_a($v1,$v2,TRUE) );&lt;br /&gt;
    $s4 = YesNo( is_subclass_of($v1,$v2,FALSE) );&lt;br /&gt;
    $s5 = YesNo( is_subclass_of($v1,$v2,TRUE) );&lt;br /&gt;
&lt;br /&gt;
    return ROW_OPEN&lt;br /&gt;
      .Cell($sDesc)&lt;br /&gt;
      .CELL_OPEN.$s1.CELL_SHUT&lt;br /&gt;
      .CELL_OPEN.$s2.CELL_SHUT&lt;br /&gt;
      .CELL_OPEN.$s3.CELL_SHUT&lt;br /&gt;
      .CELL_OPEN.$s4.CELL_SHUT&lt;br /&gt;
      .CELL_OPEN.$s5.CELL_SHUT&lt;br /&gt;
      .ROW_SHUT&lt;br /&gt;
      ;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo &amp;#039;Class Inheritance Functions Testing&amp;#039;.CRLF;&lt;br /&gt;
&lt;br /&gt;
echo TABLE_OPEN;&lt;br /&gt;
&lt;br /&gt;
echo WholeRow(&amp;#039;compare things to cA&amp;#039;);&lt;br /&gt;
echo RenderRow(&amp;#039;cA, cA&amp;#039;,cA::class,cA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;cB, cA&amp;#039;,cB::class,cA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oA, cA&amp;#039;,$oA,     cA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oB, cA&amp;#039;,$oB,     cA::class);&lt;br /&gt;
&lt;br /&gt;
echo WholeRow(&amp;#039;compare things to iA&amp;#039;);&lt;br /&gt;
echo RenderRow(&amp;#039;cA, iA&amp;#039;,cA::class,iA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oA, iA&amp;#039;,$oA,     iA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;cB, iA&amp;#039;,cB::class,iA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oB, iA&amp;#039;,$oB,     iA::class);&lt;br /&gt;
&lt;br /&gt;
echo WholeRow(&amp;#039;compare things to iB&amp;#039;);&lt;br /&gt;
echo RenderRow(&amp;#039;cB, iB&amp;#039;,cB::class,iB::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oB, iB&amp;#039;,$oB,     iB::class);&lt;br /&gt;
&lt;br /&gt;
echo WholeRow(&amp;#039;compare things to tA&amp;#039;);&lt;br /&gt;
echo RenderRow(&amp;#039;cA, tA&amp;#039;,cA::class,tA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;cB, tA&amp;#039;,cB::class,tA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oB, tA&amp;#039;,$oB,tA::class);&lt;br /&gt;
&lt;br /&gt;
echo WholeRow(&amp;#039;compare xD to things (should always be FALSE)&amp;#039;);&lt;br /&gt;
echo RenderRow(&amp;#039;cD, cA&amp;#039;,cD::class,cA::class);&lt;br /&gt;
echo RenderRow(&amp;#039;$oD, cA&amp;#039;,$oD,cA::class);&lt;br /&gt;
&lt;br /&gt;
echo TABLE_SHUT;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Woozle</name></author>
	</entry>
</feed>