From ed4091f0c223a634da0acce2bfe032baeca83a22 Mon Sep 17 00:00:00 2001 From: George Peter Banyard <7906688+Girgias@users.noreply.github.com> Date: Tue, 5 Jan 2021 22:45:25 +0000 Subject: [PATCH] Use `const` for constants instead of define() Move ``define()`` to a new section about Runtime defined constants. --- php.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/php.md b/php.md index 0c5370f..80199d1 100644 --- a/php.md +++ b/php.md @@ -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 {