Assigning const value to const error in php

北慕城南 提交于 2019-12-11 06:05:54

问题


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

Parse error: syntax error, unexpected '(', expecting ',' or ';' on line 4

What's the problem with it?


回答1:


From the documentation:

The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.

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




回答2:


mb

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


来源:https://stackoverflow.com/questions/2511906/assigning-const-value-to-const-error-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!