note 129349 added to function.is-subclass-of
| From: | Shane | Date: | Sat, 23 Mar 2024 13:26:18 +0000 |
| Subject: | note 129349 added to function.is-subclass-of | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221255@lists.php.net to get a copy of this message | ||
In addition to Anonymous's post above regarding using this to determine whether your class has
been inherited or not, you may also use this in static methods as follows:
<?php
class a {
public static function check() {
return is_subclass_of(static::class, self::class);
}
}
class b extends a {}
echo a::check() ? "Yes" : "No";
echo PHP_EOL;
echo b::check() ? "Yes" : "No";
echo PHP_EOL;
?>
Prints:
No
Yes
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 161.8.228.28)
----
Manual Page -- https://php.net/manual/en/function.is-subclass-of.php
Edit -- https://main.php.net/note/edit/129349
Del: integrated -- https://main.php.net/note/delete/129349/integrated
Del: useless -- https://main.php.net/note/delete/129349/useless
Del: bad code -- https://main.php.net/note/delete/129349/bad+code
Del: spam -- https://main.php.net/note/delete/129349/spam
Del: non-english -- https://main.php.net/note/delete/129349/non-english
Del: in docs -- https://main.php.net/note/delete/129349/in+docs
Del: other reasons-- https://main.php.net/note/delete/129349
Reject -- https://main.php.net/note/reject/129349
Search -- https://main.php.net/manage/user-notes.php