使用 trait 时报PHP Parse error: syntax error, unexpected 'use' (T_USE) 这个错误
找一大圈原因, 最后终于找到了, 不是PHP版本的原因[], 是自己把use 写到了类里的方法里了.
这个东东, 不能脱离类单独使用, 否则的话, 会被认为是命名空间了.
测试例子如下
// Trait.php
trait CustomerFunctionsTrait {
public function plus ( $a = 1, $b = 1 ) {
echo $a + $b;
}
public function minus ( $a = 5, $b = 1 ) {
echo $a - $b;
}
}
// Test.php
include './Trait.php';
class MyTest {
use CustomerFunctionsTrait;
public function plus () {
// use CustomerFunctionsTrait; //这是我错的地方, 把use 写到方法体里了 - -!!
echo 'str';
}
}
$n = new MyTest;
$n->minus();
使用 trait 时报PHP Parse error: syntax error, unexpected 'use' (T_USE) 这个错误的更多相关文章
- Parse error: syntax error, unexpected '__data' (T_STRING), expecting ',' or ')'
使用laravel时,建立view文件引入dafault文件时报错: Parse error: syntax error, unexpected '__data' (T_STRING), expect ...
- Parse error: syntax error, unexpected T_PUBLIC in 问题解决
class 类中 public function _getInfo($sn){ $title = ''; $_array = explode('~', $sn); ...
- *2 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '[' in /application/nginx-1.6.3/html/zabbix/index.php on line 32" while reading response header from upstream, clien
今天呢想学习一下zabbix监控一下我的服务情况,然后就开始安装我的zabbix服务,首先LNMP环境准备好了,Nginx版本为1.6.3,php版本为5.3.27,MySQL版本为二进制包安装的5. ...
- zabbix3.0 安装时出现PHP Parse error: syntax error
httpd的错误日志 [Sun Mar :: ] [error] [client 由于系统yum默认安装的php版本是5.3.3 zabbix 3.0支持的平台,只支持php5.4以上的版本https ...
- 页面白屏并且报错PHP Parse error: syntax error, unexpected end of file in 试了很久总算解决了
页面白屏并且报错PHP Parse error: syntax error, unexpected end of file in 试了很久 啥短标记,打开,都试了 最简单的办法 是重新建立一个文件, ...
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
出现这个错误的原因就是语法错误,肯定是PHP程序的书写不规范造成,PHP语句标识符错了,没有在php.ini中开启短标签!八成是这个原因,啊啊啊! 今天在写PHP程序的时候总是出现这样的错误:Pars ...
- Parse error: syntax error, unexpected end of file in *.php on line * 解决方法
Parse error: syntax error, unexpected end of file in *.php on line * 解决方法 这篇文章主要介绍了PHP错误Parse erro ...
- thinkphp6安装报错,composer install tp6 报错 Parse error: syntax error
composer install thinkphp6 报错 Parse error: syntax error, unexpected ':', expecting '{' in vendor\top ...
- Parse error: syntax error, unexpected 'class' (T_CLASS)
电脑坏了重新下载代码. 结果报错 Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_ST ...
- 使用帝国备份王软件提示 Parse error: syntax error, unexpected end of file
使用帝国备份王软件提示 Parse error: syntax error, unexpected end of file时, 可以尝试一下方法: 1.php.ini要把short_open_tag ...
随机推荐
- 去除后台ckeditor的style="...."的样式
.cnt_text .text img {/*width :auto !important;*/height :auto !important; max-width:660px;} 高度自适应,高度让 ...
- DedeCMS时间格式
时间格式 {dede:field name='pubdate' function='strftime("%Y年%m月%d日 %H:%M:%S","@me")' ...
- YII 小部件实现Area textArea
<?php echo $form->textArea($user_model,'introduce',array('cols'=>50,'rows'=>5)); ?>
- ha666_go运行环境配置
项目地址:http://git.oschina.net/ha666/ha666_go 服务器配置: CPU: 1核 内存: 1024 MB 操作系统: CentOS 7.0 64位 内网IP: 10. ...
- MySql可视化工具MySQL Workbench使用教程
1. MySQL Workbench MySQL Workbench 为数据库管理员.程序开发者和系统规划师提供可视化的Sql开发.数据库建模.以及数据库管理功能. 2.MySQL Workbench ...
- Hibernate 配置详解(5)
9) hibernate.batch_fetch_style: 该配置是hibernate4.2.0新添加的,使用这个设置可以配置hibernate在做batch-fetch的时候,生成SQL的策略. ...
- 【HDOJ】2609 How many
循环同构的最小表示法. #include <cstdio> #include <cstring> #define MAXN 10005 #define MAXL 105 cha ...
- bzoj3275
容易想到是最小割(最大权独立集)然后每个数拆成两个点,不能同时选的之间连边跑最小割,最后答案=总数-mincut/2 因为这样建图将流量变成了原来的两倍 当然这道题更好的建图方法是分成奇数和偶数两个集 ...
- Invert Binary Tree——LeetCode
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- BFS 10.1.5.253 1502
http://10.1.5.253/acmhome/problemdetail.do?&method=showdetail&id=1502 //1502 #include <st ...