PHP语法错误求助:unexpected T_CONSTANT_ENCAPSED_STRING报错排查
PHP语法错误修复:第89行意外字符串问题
报错信息:
PHP Parse error: syntax error, unexpected '"."' (T_CONSTANT_ENCAPSED_STRING), expecting ';' in /home/yKJgGf/prog.php on line 89
错误原因
第89行的__toString方法中,return语句的字符串拼接缺少了连接运算符.。原代码里$this->name与后面的"."之间没有用.连接,PHP无法解析这种语法。
修复后的代码
class Animal{ public $name; public $color; public function __construct($name,$color){ $this->name = $name; $this->color = $color; } public function intro(){ echo "<br> The animal is {$this->name} and the color is {$this->color}."; } public function __toString() { //89th line return "Name of the object is " . $this->name . "."; } }
内容的提问来源于stack exchange,提问作者Gizemitto
相关产品推荐
相关产品推荐

