PHP-constant():定数値を返します


PHP関数
constant
サマリ
定数値を返します.
関数プロトタイプ
constant ( string $name ) : mixed
パラメータ$name定数名.
説明:
PHP 4.0.4から提供されます.
は、ていすうという名前の値を返します.constant()は、定数値を検索する必要があるが、名前が分からない場合に便利です.
変数に格納するか、関数によって返されます.
この関数はクラス定数とともに動作します.
定数値を返すか、定数が定義されていない場合は、nullを返します.
定数が定義されていない場合は、E_WARNINGレベルのエラーが発生します.
define("MAXSIZE", 100);

echo MAXSIZE;
echo constant("MAXSIZE"); // same thing as the previous line


interface bar {
    const test = 'foobar!';
}

class foo {
    const test = 'foobar!';
}

$const = 'test';

var_dump(constant('bar::'. $const)); // string(7) "foobar!"
var_dump(constant('foo::'. $const)); // string(7) "foobar!"
リファレンス
https://phpman.ml/constant
https://www.php.net/manual/en/function.constant.php
そうかんかんすう
define
defined
copyright phpman all right reserved
インスタントレコーダ uses phpman 's content under contract.
インスタントレコーダで開発依頼を要求する場合は、FAQを参照してください.適切であれば、[email protected]に連絡してください.