/* define()関数を使った宣言例 */
define('GLOBAL_CONSTANT', 200);
echo GLOBAL_CONSTANT; // 200

/* クラス内でconstキーワードを使った宣言例 */
class MyClass {
    const CONSTANT = 'constant value';

    function showConstant() {
        echo self::CONSTANT . "\n";
    }
}
echo MyClass::CONSTANT; // 'constant value'

$class = new MyClass();
$class->showConstant(); // 'constant value'
define('STATUS_ACTIVE', 1);
define('STATUS_INACTIVE', 2);
define('STATUS_ARCHIVED', 3);
define('MAX_LOGIN_ATTEMPTS', 5);
// 定数を使う場合
define('TAX_RATE', 0.1);
$totalAmount = $subTotal + ($subTotal * TAX_RATE);

// 定数を使わない場合
$taxRate = 0.1;
$totalAmount = $subTotal + ($subTotal * $taxRate);
define(string $constant_name, mixed $value, bool $case_insensitive = false): bool
define('MY_CONSTANT', 10);
echo MY_CONSTANT // 出力: 10
class MyClass {
    const CLASS_CONSTANT = 100;

    public function getConstantValue() {
        return self::CLASS_CONSTANT; // self::CONSTANT_NAME の形式でアクセス可能
    }
}
echo MyClass::CLASS_CONSTANT; // 出力: 100、クラス名と :: 演算子を使ってアクセスできます
define('GLOBAL_CONSTANT', 200);

class AnotherClass {
    public function getConstantValue() {
        return GLOBAL_CONSTANT;
    }
}

echo GLOBAL_CONSTANT; // 出力: 200

$anotherClass = new AnotherClass();
echo $anotherClass->getConstantValue(); // 出力: 200
class MyClass {
    const CLASS_CONSTANT = 100;
}

echo MyClass::CLASS_CONSTANT; // 出力: 100

// クラス内定数を直接使用すると警告が発生します
// echo CLASS_CONSTANT; // 警告: Use of undefined constant CLASS_CONSTANT - assumed 'CLASS_CONSTANT'
define('FRUITS', ['apple', 'orange', 'banana']);
echo FRUITS[0]; // 出力: apple
define('FRUITS', ['apple', 'orange', 'banana']);
FRUITS[0] = 'grape'; // Fatal Eror