在php中为const错误分配const值

时间:2010-03-24 22:30:21

标签: php language-features constants

<?php
 class Lala {
  const a = "a";
  const b = a . "b";
 }
?>

解析错误:语法错误,意外'(',期待','或';'第4行

它有什么问题?

2 个答案:

答案 0 :(得分:7)

来自文档:

  

值必须是常量表达式,而不是(例如)变量,属性,数学运算的结果或函数调用。

请参阅http://www.php.net/manual/en/language.oop5.constants.php

答案 1 :(得分:2)

mb

<?php
 class Lala {
  const A = "a";
  const B = self::A . "b";
 }
?>
相关问题