你不能在这样的类中声明属性。类的成员可以是数据成员(常量和属性)或方法。在 PHP 5 的做事方式中,它基本上是这样工作的:
// de facto best practice: class names start with uppercase letter
class Abc
{
// de facto best practice: ALL UPPERCASE letters for constants
const SOME_COSTANT = 'this value is immutable'; // accessible outside and inside this class like Abc::SOME_CONSTANT or inside this class like self::SOME_CONSTANT
public $a = 'Hello'; // a data member that is accessible to all
protected $b = 'Hi'; // a data membet that is accessible to this class, and classes that extend this class
private $c = 'Howdy'; // a data member that is accessible only to this class
// visibility keywords apply here also
public function aMethod( $with, $some, $parameters ) // a method
{
/* do something */
}
}
你真的不应该考虑使用 php 4 用关键字声明数据成员的做法var
,除非你当然还在为 php 4 开发。