From 458b861380c0d2dcdefcc2c2cf3e869cd6f36891 Mon Sep 17 00:00:00 2001 From: George-Cristian Tudoran <4936352+Gasjki@users.noreply.github.com> Date: Mon, 12 Nov 2018 12:55:12 +0200 Subject: [PATCH] Added class constants (#21662) * Added class constants * fix(guide): typos --- guide/english/php/constants/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guide/english/php/constants/index.md b/guide/english/php/constants/index.md index e580e1364b..d49eab7deb 100644 --- a/guide/english/php/constants/index.md +++ b/guide/english/php/constants/index.md @@ -18,6 +18,21 @@ echo freeCodeCamp; Learn to code and help nonprofits ``` +Also, when you are creating classes, you can declare your own constants. + +```php +class Human { + const TYPE_MALE = 'm'; + const TYPE_FEMALE = 'f'; + const TYPE_UNKNOWN = 'u'; // When user didn't select his gender + + ............. +} +``` + +**Note:** If you want to use those constants inside the `Human` class, you can refer them as `self::CONSTANT_NAME`. If you want to use them outside the class, you need to refer them as `Human::CONSTANT_NAME`. + #### More Information: * php.net constants manual * php.net define() manual +* Create your first PHP class