Wednesday, 21 March 2018

php concatenating string to classconstant in array assignment



following doesn't work:




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');

Answer




can somebody tell me why that is?




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


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...