mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
Use const for constants instead of define()
Move ``define()`` to a new section about Runtime defined constants.
This commit is contained in:
1 parent
4e8b42d827
commit
ed4091f0c2
1 file changed
+15
-1
@@ -148,7 +148,7 @@ See: [Functions](#functions-3)
|
||||
|
||||
### Constants
|
||||
```php
|
||||
define("MY_CONST", "hello");
|
||||
const MY_CONST = "hello";
|
||||
|
||||
echo MY_CONST; # => hello
|
||||
|
||||
@@ -157,6 +157,20 @@ echo 'MY_CONST is: ' . MY_CONST;
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Runtime defined Constants
|
||||
```php
|
||||
define("CURRENT_DATE", date('Y-m-d'));
|
||||
|
||||
// One possible representation
|
||||
echo CURRENT_DATE; # => 2021-01-05
|
||||
|
||||
# => CURRENT_DATE is: 2021-01-05
|
||||
echo 'CURRENT_DATE is: ' . CURRENT_DATE;
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Classes
|
||||
```php
|
||||
class Student {
|
||||
|
||||
Reference in new issue
Block a user