<?php
trait AttributesTrait
{ /**
* 获取公共属性的方法
* $obj object 对象
*/
function publics($obj)
{ // 判断传递判断传递的
if(!is_object($obj)) return array();
return json_decode(json_encode($obj), true);
}
}
class User
{
use AttributesTrait;
public $name = "kingmax";
private $_age = 30;
}
$User = new User();
$data = $User->publics($User);
$ret = get_object_vars($User);
print_r($data);