note 129418 added to function.defined
| From: | PieterFrenssen | Date: | Fri, 19 Apr 2024 20:54:05 +0000 |
| Subject: | note 129418 added to function.defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221298@lists.php.net to get a copy of this message | ||
To check in a trait if a constant is defined in the class using the trait, prepend the constant name
with
self::class:
<?php
trait MyTrait {
public function checkConstant() {
assert(defined(self::class . "::MY_CONSTANT"));
print self::MY_CONSTANT;
}
}
class MyClass {
use MyTrait;
protected const MY_CONSTANT = 'my value';
}
$class = new MyClass();
$class->checkConstant();
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 92.247.221.20)
----
Manual Page -- https://php.net/manual/en/function.defined.php
Edit -- https://main.php.net/note/edit/129418
Del: integrated -- https://main.php.net/note/delete/129418/integrated
Del: useless -- https://main.php.net/note/delete/129418/useless
Del: bad code -- https://main.php.net/note/delete/129418/bad+code
Del: spam -- https://main.php.net/note/delete/129418/spam
Del: non-english -- https://main.php.net/note/delete/129418/non-english
Del: in docs -- https://main.php.net/note/delete/129418/in+docs
Del: other reasons-- https://main.php.net/note/delete/129418
Reject -- https://main.php.net/note/reject/129418
Search -- https://main.php.net/manage/user-notes.php