0

following doesn't work:

<?php
class test{
    const t = 10;
    public static $y = array('t' => self::t . 'hello');
}
var_dump(test::$y);
?>

can somebody tell me why that is? :)

it fails in the ... => self::t . 'hello')... part, where it, as seams, not is able to concatenate a classconstant in the array().

that implies that both of following works perfect:

public static $y = array('t' => self::t);

and

public static $y = array('t' => 'hello');
Mads Buch
  • 344
  • 2
  • 10
  • Always add your error message. And if you paste it into the search box even, you will get ca. 999 questions which are similar, if not even exactly like yours. – hakre Apr 10 '12 at 16:02

1 Answers1

1

can somebody tell me why that is?

Concatenation is a product of run-time. Class member initial values must be known at parse time.

webbiedave
  • 48,414
  • 8
  • 88
  • 101