You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
547 B

<?php
define('a','1');
const b=2;
echo a.'<br>'; //常量没有$号
echo b.'<br>';
//b=3; //b是常量,不能再修改
//echo b;
//获取常量
$b='b';
echo constant($b).'<br>';
//判断常量是否存在
const c=3;
$d=4;
var_dump(defined('c')); //常量c存在,返回true
echo '<br>';
var_dump(defined('d')); //d不是常量,返回false
echo '<br>';
//魔术常量
echo "当前文件路径".__FILE__;
/*
感悟:php常量像C语言里的宏
*/
?>