note 120113 added to function.constant
| From: | helvete at zhouba dot cz | Date: | Thu, 03 Nov 2016 11:08:13 +0000 |
| Subject: | note 120113 added to function.constant | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-207008@lists.php.net to get a copy of this message | ||
It is worth noting, that keyword 'self' can be used for constant retrieval from within the
class it is defined
<?php
class Foo {
const PARAM_BAR = 'baz';
public function getConst($name) {
return constant("self::{$name}");
}
}
$foo = new Foo();
echo $foo->getConst('PARAM_BAR'); // prints 'baz'
?>
----
Server IP: 72.52.91.14
Probable Submitter: 176.62.235.194
----
Manual Page -- http://php.net/manual/en/function.constant.php
Edit -- https://master.php.net/note/edit/120113
Del: integrated -- https://master.php.net/note/delete/120113/integrated
Del: useless -- https://master.php.net/note/delete/120113/useless
Del: bad code -- https://master.php.net/note/delete/120113/bad+code
Del: spam -- https://master.php.net/note/delete/120113/spam
Del: non-english -- https://master.php.net/note/delete/120113/non-english
Del: in docs -- https://master.php.net/note/delete/120113/in+docs
Del: other reasons-- https://master.php.net/note/delete/120113
Reject -- https://master.php.net/note/reject/120113
Search -- https://master.php.net/manage/user-notes.php