This code gives the error “unexpected ‘.’, expecting ‘)'”. Why is this invalid? I’d thought that as both parts are constant, I could concatenate them. New to PHP. Thanks.
class c {
const HELLO = 'hello';
public $arr = array(
'hw' => self::HELLO . 'world'
);
}
Class properties must have constant initial values. The concatenation of those two strings is NOT a constant value.
From the documentation:
You could put the property initialisation in your constructor: