views:

57

answers:

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

+7  A: 

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

Nicolò Martini
+2  A: 

mb

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