开发者

Assigning const value to const error in php

开发者 https://www.devze.com 2022-12-24 05:55 出处:网络
<?php class Lala { const a = \"a\"; const b = a . \"b\"; } ?> Parse error: syntax error, unexpected \'(\', expecting \',\' or 开发者_开发知识库\';\' on line 4
<?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?


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


mb

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

精彩评论

暂无评论...
验证码 换一张
取 消