【问题标题】:Assigning const value to const error in php将 const 值分配给 php 中的 const 错误
【发布时间】:2011-01-31 11:58:48
【问题描述】:
<?php
 class Lala {
  const a = "a";
  const b = a . "b";
 }
?>

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

它有什么问题?

【问题讨论】:

标签: php language-features constants


【解决方案1】:

来自文档:

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

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

【讨论】:

    【解决方案2】:

    mb

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

    【讨论】:

    • 这是不正确的。 const 不能是表达式的结果。
    猜你喜欢
    • 2011-06-25
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多