note 126727 added to language.constants.syntax
| From: | souzanicolas87 at gmail dot com | Date: | Wed, 29 Dec 2021 12:17:40 +0000 |
| Subject: | note 126727 added to language.constants.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217439@lists.php.net to get a copy of this message | ||
the documentation doesn't go too far in explaining the crucial difference between the two ways
of declaring constants in PHP.
Const is handled at compile time, define() at run time. For this reason, a constant cannot be
conditionally defined using Const, for example.
Another difference we can notice occurs in the constant declarations in classes. Const infiltrates
the class scope, while define() leaks into the global scope.
<?php
Class Myclass (){
const NAME = "Nicolas";
}
?>
The NAME constant is within the scope of the MyClass class.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 168.90.219.236)
----
Manual Page -- https://php.net/manual/en/language.constants.syntax.php
Edit -- https://main.php.net/note/edit/126727
Del: integrated -- https://main.php.net/note/delete/126727/integrated
Del: useless -- https://main.php.net/note/delete/126727/useless
Del: bad code -- https://main.php.net/note/delete/126727/bad+code
Del: spam -- https://main.php.net/note/delete/126727/spam
Del: non-english -- https://main.php.net/note/delete/126727/non-english
Del: in docs -- https://main.php.net/note/delete/126727/in+docs
Del: other reasons-- https://main.php.net/note/delete/126727
Reject -- https://main.php.net/note/reject/126727
Search -- https://main.php.net/manage/user-notes.php