A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren't actually constants). Constants are case-sensitive. By convention, constant identifiers are always uppercase.
/**
*
* in this code example is very hard to find out what 1 actually means ...
*
*/
$status = (int)$args['status'];
switch ($status) {
case 1:
$notifier = $this->SendPendingNotification();
break;
case 2:
$notifier = $this->SendAcceptedNotification();
break;
case 3:
$notifier = $this->SendRejectedNotification();
break;
case 4:
$notifier = $this->SendBlockedNotification();
break;
}
/**
*
* Define in body of class
* const PENDING = 1;
* const ACCEPTED = 2;
* const REJECTED = 3;
* const BLOCKED = 4;
*
* This code is self explanatory , the constants are in fact numbers but tell you what they are
*
*/
$status = (int)$args['status'];
switch ($status) {
case self::PENDING:
$notifier = $this->SendPendingNotification();
break;
case self::ACCEPTED:
$notifier = $this->SendAcceptedNotification();
break;
case self::REJECTED:
$notifier = $this->SendRejectedNotification();
break;
case self::BLOCKED:
$notifier = $this->SendBlockedNotification();
break;
}
LLoadout is your loadout for Laravel, helping you kickstart your development process. Besides this refactoring site we also make some cool packages and video tutorials !
Go to LLoadout on github