json - Set a variable to what json_encode() outputs in PHP -
json_encode() returns string...
so shouldn't following code work?
class testclass { private $test = json_encode("test"); } php outputs
parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/testuser/public_html/test.php on line 10
you can not assign expression or variable while declaring class property. literal constants such __file__ allowed here.
they have literal value, such string, or constant.
there work.
private $test= 98; private $test= "test value"; private $test= constant; private $test= __file__; but these not
private $test= 98*2; private $test= "test value"."some other value"; you can use constructor
function __construct() { $this->test = json_encode("test"); }
Comments
Post a Comment