PHP/inheritance

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
Revision as of 12:35, 5 April 2024 by Woozle (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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