加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP解析错误:语法错误,意外T_PUBLIC [已关闭]

发布时间:2020-12-13 16:32:14 所属栏目:PHP教程 来源:网络整理
导读:我在第3行的 PHP代码中收到此错误,可能是错误的?此代码已从php手册 user notes by frank at interactinet dot com中获取 ?phppublic function myMethod(){return 'test';}public function myOtherMethod(){return null;}if($val = $this-myMethod()){ // $v
我在第3行的 PHP代码中收到此错误,可能是错误的?此代码已从php手册 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关键字仅在类中的函数/变量声明中使用.由于您没有使用课程,因此您需要从代码中删除它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读