我正在尝试编写一个脚本来检查我的PHP类文件是否与MySQL数据库表模式匹配。检查PHP类完整性的方法
数据库表“品牌”
Column Type Null Extra Key
==============================================================
id INT(11) NO AUTO_INCREMENT Primary
brand_name VARCHAR(50) NO
founded INT(11) NO
status INT(11) NO Default: 1
created_on DATETIME NO
updated_on DATETIME NO
而且我的PHP类文件“Brand.php”是如下:
<?php
class Brand {
public $id;
public $brand_name;
public $founded;
public $status;
public $created_on;
public $updated_on;
public function __construct() {
// constructor here
}
}
?>
什么是检查相应的属性存在或不是最好的方法?
一种方法我想到的是使用PHP脚本来检查上面的PHP类:
一个使用get_object_vars($obj)的缺点是,这个功能只能得到公共属性,它被称为外类。任何更好的选择?
由于我使用的是基于Unix的系统,所以使用shell脚本也是可行的。
[思考](http://www.php.net/manual/en/reflectionclass.getproperties.php)让你看一个类的属性,无论是公共/保护/私人 –
'ReflectionClass'似乎很有希望,谢谢! – Raptor
@MarkBaker请添加您的建议作为答案,谢谢:) – Raptor