[我知道我应该习惯它,但也许有办法强制执行名称检查?]
谢谢!
编辑:对不起,那不是很具体.这是代码,我想得到两个错误.现在我只得到一个(最后一行).
error_reporting(E_ALL|E_STRICT); class Joe { public $lastName; } $joe = new Joe(); $joe->lastNombre = "Smith"; echo "And here it is " . $jose;
[我知道我应该习惯它,但也许有办法强制执行名称检查?]
谢谢!
编辑:对不起,那不是很具体.这是代码,我想得到两个错误.现在我只得到一个(最后一行).
error_reporting(E_ALL|E_STRICT); class Joe { public $lastName; } $joe = new Joe(); $joe->lastNombre = "Smith"; echo "And here it is " . $jose;
<?PHP error_reporting( E_ALL | E_STRICT ); class Joe { public $lastName; public function __set( $name,$value ) { if ( !property_exists( $this,$name ) ) { trigger_error( 'Undefined property via __set(): ' . $name,E_USER_NOTICE ); return null; } $this->$name = $value; } public function __get( $name ) { if ( !property_exists( $this,$name ) ) { trigger_error( 'Undefined property via __get(): ' . $name,E_USER_NOTICE ); return null; } return $this->$name; } } $joe = new Joe(); $joe->lastNom = "Smith"; echo $joe->lastNom,"\n"; ?>