一、不能在成员函数中定义常量,否则会引发诡异地语法错误 syntax error, unexpected 'CONST' (T_CONST)

示例

/* 错误的方式 */
class A
{
public function myfunction()
{
const CONST_VAR = 0;
}
} /* 正确的方式 */
class A
{
const CONST_VAR = 0;
public function myfunction()
{
echo self::CONST_VAR; }
}

二、不能使用public  protected private  static等修饰符。

示例

/* 错误的方式 */
class A
{
public static const CONST_VAR;
private const CONST_VAR2;
} /* 正确的方式 */
class A
{
const CONST_VAR;
const CONST_VAR2;
}

PHP:在class中定义常量注意事项的更多相关文章

  1. 在php中定义常量时,const与define的区别?

    问]在php中定义常量时,const与define的区别?  [答]使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很 ...

  2. 在C++中定义常量的两种方法的比较

    常量是定以后,在程序运行中不能被改变的标识符.C++中定义常量可以用#define .const 这两种方法.例如:#define PRICE 10 //定义单价常量10const int PRICE ...

  3. PHP中定义常量的几种方式与区别

    [问]在php中定义常量时,const与define的区别? [答]使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很 ...

  4. Java中定义常量方法及建议(Class/Interface)

    Class定义常量方法(推荐方法) //final修饰符 public final class Constants { //私有构造方法 private Constants() {} public s ...

  5. PHP中定义常量

    PHP中定义常量的方式如下: define(常量名,常量值); //定义常量PUBLISHER define('PUBLISHER', "O'Reilly & Associates& ...

  6. PHP中定义常量的区别,define() 与 const

      正文 在PHP5.3中,有两种方法可以定义常量: 使用const关键字 使用define()方法 const FOO = 'BAR'; define('FOO','BAR'); 这两种方式的根本区 ...

  7. 在php中定义常量时,const和define的区别?

    使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很多. 1.const用于类成员变量的定义,一经定义,不可修改.Def ...

  8. Java中定义常量(Constant) 的几种方法

    为了方便大家交流Spark大数据,浪尖建了微信群,目前人数过多,只能通过浪尖或者在群里的朋友拉入群.纯技术交流,偶有吹水,但是打广告,不提醒,直接踢出.有兴趣加浪尖微信. 常量使用目的 1,为什么要将 ...

  9. 在C++中定义常量

    在 C++ 中,有两种简单的定义常量的方式: 使用 #define 预处理器. 使用 const 关键字 使用 #define 预处理器: #define identifier value: #inc ...

随机推荐

  1. HJ浇花

    题目描述 HJ养了很多花(99999999999999999999999999999999999盆),并且喜欢把它们排成一排,编号0~999999999999999999999999999999999 ...

  2. dts--tests(三)

    sample_built.py """ DPDK Test suite. Test sample_built. """ import uti ...

  3. keil 使用C++编程主要要点

    1.中断处理,添加一下宏定义.如果不添加,中断服务函数不会链接到下载文件中:发生中断后,会停留在xxx.s文件的 "B ."语句. #ifdef __cplusplus exter ...

  4. cf978E Bus Video System

    The busses in Berland are equipped with a video surveillance system. The system records information ...

  5. RSA前端加密解密

    技术交流群: 233513714 <html> <head> <title>JavaScript RSA Encryption</title> < ...

  6. css3 3D

    开通黄钻 Css3 -3D效果<!DOCTYPE html><html lang="en"><head> <meta charset=&q ...

  7. how to export chrome speed dial extension?

    locate chrome-extension_dgpdioedihjhncjafcpgbbjdpbbkikmi_0.localstorage, copy it to you want, everyt ...

  8. 《Cracking the Coding Interview》——第5章:位操作——题目2

    2014-03-19 05:47 题目:给定一个double型浮点数,输出其二进制表示,如果不能在32个字符内完成输出,则输出“ERROR”. 解法:如果你熟悉IEEE754标准,应该知道double ...

  9. USACO Section1.3 Combination Lock 解题报告

    combo解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  10. shell脚本简单切割字符串

    我们有这样一个字符串: info='abcd;efgh' 现在想获取abcd和efgh,我们可以简单地用cut工具来获取: fstr=`` sstr=`` 这里主要是用了cut工具的-d和-f参数: ...