php 解析错误:语法错误,意外(T_STRING),期望变量(T_VARIABLE)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21930748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:32:49  来源:igfitidea点击:

Parse error: syntax error, unexpected (T_STRING), expecting variable (T_VARIABLE)

phpclassoopinheritance

提问by Pax

I will be grateful if someone can point out where the error is occurring.

如果有人能指出错误发生的位置,我将不胜感激。

class hotel extends WishDBxyz{ 
 public nomhotel;
 protected idhotel, ile_idile, pays_idpays, chainehotel_idchainehotel, actif ;
} 

Just on second line got the error Parse error: syntax error, unexpected (T_STRING), expecting variable (T_VARIABLE). I'm quite new to Object Oriented PHP and writting one class inheriting another class.

就在第二行出现错误解析错误:语法错误,意外(T_STRING),期望变量(T_VARIABLE)。我对面向对象的 PHP 很陌生,正在编写一个继承另一个类的类。

回答by Codrutz Codrutz

Those are variables in php.So add the $sign:

这些是php中的变量。所以添加$符号:

class hotel extends WishDBxyz{ 
 public $nomhotel;
 protected $idhotel, $ile_idile, $pays_idpays, $chainehotel_idchainehotel, $actif ;
}

回答by po_taka

回答by Dexture

You are missing $ in variables

你在变量中缺少 $

class hotel extends WishDBxyz{ 
 public $nomhotel;
 protected $idhotel, $ile_idile, $pays_idpays, $chainehotel_idchainehotel, $actif ;
}

回答by Sutandiono

From the PHP manual page:

PHP 手册页

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

PHP 中的变量由美元符号后跟变量名称表示。变量名区分大小写。

So for your case, you'd put something like:

因此,对于您的情况,您可以输入以下内容:

class Hotel extends WishDBxyz{ 
    public $nomhotel;
    protected $idhotel, $ile_idile, $pays_idpays, $chainehotel_idchainehotel, $actif ;
}

For examples on declaring classes, properties, methods, etc., look at the PHP manual.

有关声明类、属性、方法等的示例,请查看PHP 手册

(As a habit, I usually use UpperCamelCasefor the class name)

(作为习惯,我通常使用大驼峰作为类名)

回答by SajithNair

Variable names should be prefixed with $

变量名应以 $ 为前缀