constant

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

constant锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷值

说锟斤拷

constant ( string $name ) : mixed

通锟斤拷 name 锟斤拷锟截筹拷锟斤拷锟斤拷值锟斤拷

锟斤拷锟姐不知锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷却锟斤拷要锟斤拷取锟斤拷锟斤拷锟斤拷值时锟斤拷constant() 锟酵猴拷锟斤拷锟斤拷锟剿★拷也锟斤拷锟角筹拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤,锟斤拷锟斤拷锟缴猴拷锟斤拷锟斤拷锟截筹拷锟斤拷锟斤拷锟斤拷

锟矫猴拷锟斤拷也锟斤拷锟斤拷 class constants锟斤拷

锟斤拷锟斤拷

name

锟斤拷锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟截筹拷锟斤拷锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷锟轿达拷锟斤拷锟斤拷蚍祷锟� NULL锟斤拷

锟斤拷锟斤拷锟届常

锟斤拷锟斤拷锟斤拷锟轿达拷锟斤拷澹拷锟斤拷锟斤拷一锟斤拷 E_WARNING 锟斤拷锟斤拷拇锟斤拷锟�

锟斤拷锟斤拷

Example #1 constant() 锟斤拷锟斤拷锟斤拷

<?php

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!"

?>

锟轿硷拷

  • define() - 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷
  • defined() - 锟斤拷锟侥筹拷锟斤拷锟斤拷频某锟斤拷锟斤拷欠锟斤拷锟斤拷
  • Constants 锟斤拷一锟斤拷