get_class_vars — Get the default properties of the class
动态定义的属性是不会被这个函数打出来的 ...
如果你需要列出一个类的所有属性 ... 一段小技巧可以帮助到你 ...
<?php
class b {
public function bind( $data ) {
foreach ( $data as $key => $value )
$this->$value = null;
/* just make an array to output like you want ... */
$ret = [];
/* no need to do type conversion here ... php will done for us ... */
foreach( $this as $key => $null_of_course )
$ret[] = $key;
/* miracle time ... */
print_r( $ret );
}
}
(new b)->bind( [
'aa' => 'bb',
'cc' => 'dd'
] );
或者更简单的写法 ... 需要手动转化一下类型 ...
$ret = array_keys( (array) $this );
By the way ... 编辑一句题外话 ... tabsize 设成 5 的习惯是哪里来的 ..?