PHP解析错误:语法错误,意外的T_PUBLIC [英] PHP Parse error: syntax error, unexpected T_PUBLIC
本文介绍了PHP解析错误:语法错误,意外的T_PUBLIC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在第3行的此PHP代码中遇到此错误,这可能是什么问题?这段代码摘自php手册用户注释,由Frankine in interactinet点com
I am getting this error in this PHP code on line 3, what could be wrong? This code has been taken from php manual user notes by frank at interactinet dot com
<?php
public function myMethod()
{
return 'test';
}
public function myOtherMethod()
{
return null;
}
if($val = $this->myMethod())
{
// $val might be 1 instead of the expected 'test'
}
if( ($val = $this->myMethod()) )
{
// now $val should be 'test'
}
// or to check for false
if( !($val = $this->myMethod()) )
{
// this will not run since $val = 'test' and equates to true
}
// this is an easy way to assign default value only if a value is not returned:
if( !($val = $this->myOtherMethod()) )
{
$val = 'default'
}
?>
推荐答案
public
关键字仅在声明类方法时使用.
The public
keyword is used only when declaring a class method.
由于您声明的是简单函数而不是类,因此需要从代码中删除public
.
Since you're declaring a simple function and not a class you need to remove public
from your code.
这篇关于PHP解析错误:语法错误,意外的T_PUBLIC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文