<?phptraitAttributesTrait{/***获取公共属性的方法*$objobject对象*/functionpublics($obj){//判断传递判断传递的if(!is_object($obj))returnarray();returnjson_decode(json_encode($obj),true);}}classUser{useAttributesTrait;public$name="kingmax";private$_age=30;}$User=newUser();$data=$User->publics($User);$ret=get_object_vars($User);print_r($data);