note 127795 added to function.is-subclass-of
| From: | Anonymous at main dot php dot net | Date: | Fri, 21 Oct 2022 11:57:59 +0000 |
| Subject: | note 127795 added to function.is-subclass-of | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219745@lists.php.net to get a copy of this message | ||
You can check if your current class is a child with:
<?php is_subclass_of($this, self::class) ?>
<?php
class a {
public function check(): bool {
return is_subclass_of($this, self::class);
}
}
class b extends a {}
$a = new a();
$b = new b();
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: 45.91.159.161 (proxied: 89.135.127.225)
----
Manual Page -- https://php.net/manual/en/function.is-subclass-of.php
Edit -- https://main.php.net/note/edit/127795
Del: integrated -- https://main.php.net/note/delete/127795/integrated
Del: useless -- https://main.php.net/note/delete/127795/useless
Del: bad code -- https://main.php.net/note/delete/127795/bad+code
Del: spam -- https://main.php.net/note/delete/127795/spam
Del: non-english -- https://main.php.net/note/delete/127795/non-english
Del: in docs -- https://main.php.net/note/delete/127795/in+docs
Del: other reasons-- https://main.php.net/note/delete/127795
Reject -- https://main.php.net/note/reject/127795
Search -- https://main.php.net/manage/user-notes.php