PHP“解析错误,需要‘T_STRING’” ” - 请帮助编写代码
我正在尝试使用 MVC 原则构建一个动态 php 网站。我在 Win XP 上使用 WAMP。
代码如下:
Index.php:
<?php
require_once("User.php");
session_start();
include ("Header.php");
include ("Footer.php");
?>
Header.php:
<?php
echo '<?xml version="1.0" encoding="utf-8"?>'
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title><?php echo "temp"; ?></title>
<link rel="stylesheet" media="screen" type="text/css" title="StyleSheetProjet" href="StyleSheetProjet.css" />
</head>
<body>
<div class="connectionStatus">
<?php
?>
</div>
Footer.php:
</body>
</html>
User.php:
<?php
class User {
private $userName;
private $hashedPassword;
private $firstName;
private $lastName;
private $userEmail;
function $getUserName() {
return $this->userName;
}
}
?>
该代码导致 User.php 第 9 行(即 get 函数声明处)出现 php 错误。错误消息是:
Parse error: parse error, expecting `T_STRING' in C:\wamp\www\Projet\User.php on line 9
非常感谢您的帮助...
谢谢,
JDelage
I'm trying to build a dynamic php site using MVC principles. I'm using WAMP on Win XP.
Here's the code:
Index.php:
<?php
require_once("User.php");
session_start();
include ("Header.php");
include ("Footer.php");
?>
Header.php:
<?php
echo '<?xml version="1.0" encoding="utf-8"?>'
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title><?php echo "temp"; ?></title>
<link rel="stylesheet" media="screen" type="text/css" title="StyleSheetProjet" href="StyleSheetProjet.css" />
</head>
<body>
<div class="connectionStatus">
<?php
?>
</div>
Footer.php:
</body>
</html>
User.php:
<?php
class User {
private $userName;
private $hashedPassword;
private $firstName;
private $lastName;
private $userEmail;
function $getUserName() {
return $this->userName;
}
}
?>
This code causes a php error on line 9 of User.php, i.e., at the get function declaration. The error message is:
Parse error: parse error, expecting `T_STRING' in C:\wamp\www\Projet\User.php on line 9
Help would be very much appreciated....
Thanks,
JDelage
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
应该
在
function
关键字之后,PHP 需要一个空格,后跟一个标识符
(函数名称)。但在您的情况下,它找到一个变量
,这会导致解析错误。在内部,标识符称为
T_STRING
,变量称为T_VARIABLE
。一些 PHP 解释器会抛出:其他,正如您的情况一样,只需说:
should be
After the
function
keyword, PHP expects a whitespace followed by anidentifier
(function name). But in your case it finds avariable
and this causes a parse error.Internally an identifier is called
T_STRING
and a variable is calledT_VARIABLE
. Some PHP interpreters throw:Others, as in your case just say:
您的函数名称有拼写错误。目前它是
$getUserName
,它应该是getUserName
(没有 $)。You have typo in your function name. Currently it's
$getUserName
where it should begetUserName
(without $).声明函数时不能使用变量替换。
这个:
应该是这个:
You can't use variable substitution when declaring functions.
This:
should be this:
函数
$
getUserName()
function
$
getUserName()
函数名称开头不需要 $ 符号。
这样做:
Function names does not need $ sign at the beginning.
Do it like that: