在PHP中根本不需要使用var声明的,但是当一个变量作为一个类的成员变量的时候,使用var还是没有问题的

其实,这是一个非常容易解决掉的问题。在我看来,似曾相识,呵呵,最近学JavaScript可是学会了使用var声明变量。

其实,在PHP中根本不需要使用var声明的,但是当一个变量作为一个类的成员变量的时候,使用var还是没有问题的。

在外部使用var就报错Parse error: syntax error, unexpected T_VAR in...,例如我的出错信息:

Parse error: syntax error, unexpected T_VAR in D:\Apache2.2\htdocs\shirdrn\page\p2\pageUtil.inc on line 34

我在测试:在一个类的内部,使用一个自己定义的类对象作为这个类的成员时,出错了。

Address类对应的address.inc代码:

代码如下:<?php

class Address {

var $road;

function Address(){}

function setRoad($road){

$this->road = $road;

}

}

?>

Person类及其测试代码为person.php如下:

代码如下:<?php

require("address.inc");

class Person {

var $name;

var $address;

function Person(){

}

function display(){

echo "Name : ".$this->name."
";

echo "Road : ".$this->address->road."
";

}

}

var $p = new Person();

$p->address = new Address();

$p->address->setRoad("Chagnchun Road");

$p->name = "Shirdrn";

$p->display();

?>

测试输出现异常:

Parse error: syntax error, unexpected T_VAR in D:\Apache2.2\htdocs\shirdrn\page\p2\pageUtil.inc on line 34

就是因为在person.php代码中使用var声明变量,PHP中是不能这样的,只要使用“$”符号起始就表示这个字符后面的是一个PHP变量。

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

php error unexpected,PHP异常Parse error: syntax error, unexpected错误解决方法相关推荐

  1. Error generating final archive: Debug Certificate expired on 的错误解决方法

    Android开发中 Error generating final archive: Debug Certificate expired on 的错误解决方法 问题概述: 在导入一个app后提示如下错 ...

  2. npm 出现Unexpected end of JSON input while parsing near错误解决方法

    npm install 的时候出现错误: npm ERR! Unexpected end of JSON input while parsing near '...","webpa ...

  3. Import error: no module named cv2 错误解决方法

    Import error: no module named cv2 错误解决方法 参考文章: (1)Import error: no module named cv2 错误解决方法 (2)https: ...

  4. HTTP 错误 500.19- Internal Server Error 错误解决方法

    HTTP 错误 500.19- Internal Server Error 错误解决方法 参考文章: (1)HTTP 错误 500.19- Internal Server Error 错误解决方法 ( ...

  5. Error parsing HTTP request header Larger错误解决方法

    Error parsing HTTP request header Larger错误解决方法 参考文章: (1)Error parsing HTTP request header Larger错误解决 ...

  6. Error, some other host already uses address 192.168.0.202错误解决方法

    Error, some other host already uses address 192.168.0.202错误解决方法 参考文章: (1)Error, some other host alre ...

  7. Xcode真机调试中“There was an internal API error“错误解决方法

    Xcode真机调试中"There was an internal API error"错误解决方法 参考文章: (1)Xcode真机调试中"There was an in ...

  8. DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016错误解决方法

    DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016错误解决方法 参考文章: (1)DB2 SQL Error: SQLCODE=-668, SQLSTATE=570 ...

  9. connection error mysql_MySQL ConnectionError 安装错误 解决方法

    MySQL ConnectionError The security settings could not be applied to the database because the connect ...

  10. win7 、2008 提示Error 1606 Could Not Access Network Location %SystemDrive%/inetpub/wwwroot/ 的错误解决方法

    win7 .2008 提示Error 1606 Could Not Access Network Location %SystemDrive%/inetpub/wwwroot/ 的错误解决方法 参考文 ...

最新文章

  1. Keras TensorFlow教程:使用自己的数据集进行训练
  2. Window 7上架设SSRS 2005时遇到的几点小麻烦
  3. 不会英语计算机开车和,驾校学车的那些事儿——技术篇
  4. 雪妖现世:给SAP Fiori Launchpad增添雪花纷飞的效果
  5. 第三部分 Calendar函数接口
  6. 高管暗示Redmi Note 10系列新品:今日有大事公布?
  7. sublime text3 保存文件时候名字后缀.dump问题解决
  8. (补充)【打印1到最大的n位数】剑指offer——面试题12:打印1到最大的n位数
  9. sql注入pythonpoco_骑士CMS后台SQL注入 | CN-SEC 中文网
  10. go语言练习:条件语句和循环语句
  11. 对话Man Group:对冲基金的达尔文式竞争
  12. visio 2003密钥
  13. python get请求下载excel,前端开发,使用get和post方式下载excel表格
  14. Unity 接入百度AI - Logo商标识别
  15. 烽火fr2600怎么web登录_烽火配置教程
  16. Retrofit,RecyclerViewMVP模式
  17. 营造美好婚姻的30个提醒
  18. 轻听-最好的解压助眠医疗轻音乐集
  19. GPS从入门到放弃(一)、GPS 定位原理
  20. access 数据计算,常用函数

热门文章

  1. 家庭收支记账软件项目【Golang-面向对象】
  2. 无法复制文件到U盘解决办法
  3. 英语听力计算机教室,每日英语听力电脑版|每日英语听力 v9.2.0 PC客户端
  4. 如何进入进计算机组策略,如何进入组策略?
  5. 模电——电阻与电容并联作用
  6. 2018年航空概论课后作业(PS:部分答案不正确, 综合得分:83.6)
  7. 选择深度学习的GPU卡
  8. latex添加代码注释_在代码中添加注释:好的,坏的和丑陋的。
  9. 《Linux内核设计与实现》第四章学习笔记——进程调度
  10. 如何删除SceneDelegate