网站制作学习网PHP→正文:php中const与define的使用区别(转)
字体:

php中const与define的使用区别(转)

PHP 2014/6/16 16:14:55  点击:不统计

学习www.网for站asp制.cn作

 1.const用于类成员变量的定义,一经定义,不可修改。define不可用于类成员变量的定义,可用于全局常量。
 
2.const可在类中使用,define不能。
 
3.const不能在条件语句中定义常量。
 
    如:if(constition){
 
                 哲理不能用const,只能用define
 
            }
 
4.const只能接受静态的标量,而define可采用任何的表达式。
 
    const BIT_5 = 1 << 5;    // invalid  
    define('BIT_5', 1 << 5); // valid 
 
5.const定义的常量时大小写敏感的,而define可通过第三个参数(为true表示大小写不敏感)来指定大小写是否敏感。
 
6.const采用一个普通的常量名称。而define可采用表达式作为常量。
 
7.使用const使得代码简单易读,const本身就是一个语言结构。而define是一个函数。
 
8.const在编译时比define快很多。

转自:http://niuyuanman.blog.163.com/blog/static/88968322012744179759/
 

·上一篇:Socket函数 >>    ·下一篇:php html生成pdf html2pdf >>
推荐文章
最新文章