php中define与const的区别

1、define不能定义在类中,const必须定义在类中,并且const必须通过类名::变量名来进行访问;

2、两者都是不能进行重新赋值。

define调用例子:

<?php
  define("TOKEN", "yooheo");
  echo TOKEN;
?>

const调用例子:

<?php
  echo testClass::TOKEN;
  class testClass{
    const TOKEN = "yooheo";
  }
?>
posted @ 2013-10-25 10:48  六十七度老白干  阅读(194)  评论(0编辑  收藏  举报