Tuesday 29 May 2018

PHP string not concatonating











I'm getting the following error:




Parse error: syntax error, unexpected '.', expecting ',' or ';' in xxx
on line 19





On this line:



public $metad_name = "lol" . "lol";

Answer



This error is saying that an expression can't be used in class properties:



Works



class Foo {


public $metad_name = '';

function __construct() {
$this->metad_name = 'lol' . 'lol';
}

}



Parse error



class Bar {

public $metad_name = 'lol' . 'lol';

}


If your code isn't a class property - just delete the public



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...