Search code examples
phplanguage-featuresconstants

Assigning const value to const error in php


<?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?


Solution

  • 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