Difference between revisions of "PHP/inheritance"
< PHP
Jump to navigation
Jump to search
(Created page with "==About== PHP includes a few bits of functionality for checking whether an object or class inherits from another classoid (class, interface, or trait). The rules for this func...") |
(No difference)
|
Revision as of 12:35, 5 April 2024
About
PHP includes a few bits of functionality for checking whether an object or class inherits from another classoid (class, interface, or trait). The rules for this functionality are not always clearly explained.
Class Inheritance Functions Testing
Here's a truth-table from PHP 8.2.10:
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) |
---|---|---|---|---|---|
cA, cA | - | - | Y | - | - |
cB, cA | - | - | Y | - | Y |
oB, cA | Y | Y | Y | Y | Y |
cA, iA | - | - | Y | - | Y |
cB, iA | - | - | Y | - | Y |
cB, iB | - | - | Y | - | Y |
oB, iA | Y | Y | Y | Y | Y |
oB, iB | Y | Y | Y | Y | Y |