打开网站显示PHP Parse error: syntax error, unexpected token "$b", expecting "," or ")" in ...(示例1);syntax error, unexpected token "echo", expecting ";" in ...错误怎么办|已解决

错误提示:PHP Parse error: syntax error, unexpected token "$b", expecting "," or ")" in ...(示例1);syntax error, unexpected token "echo", expecting ";" in ...(示例2)
原因:函数定义时,参数之间需用逗号分隔;类方法、函数体内的语句需符合基本语法(如分号、括号匹配)。
解决方案:补全参数分隔符、分号等,修正后:
<?php
// 示例1修正
function add($a, $b) {
    return $a + $b;
}
add(1,2);

// 示例2修正
class Test {
    function sayHello() {
        echo "Hello";
    }
}
$test = new Test();
$test->sayHello();
?>

 

posted @ 2026-03-13 14:39  可有仙子迎风立  阅读(30)  评论(0)    收藏  举报