<?php class user{ public $loginnum; public $ab; public function __construct($loginnum,$ab){ $this->loginnum=$loginnum; $this->ab=$ab; } public function guancha($key,$val){ $this->obj[$key]=$val; } public function zhixing(){ if($this->obj){ foreach ($this->obj as $key => $value) { $value->update($this); } } } } class ab{ public function update($obj){ var_dump($obj->ab); } } class loginnum{ public function update($obj){ var_dump($obj->loginnum); } } $user = new user(1,5); $user->guancha('ab',new ab()); $user->guancha('loginnum',new loginnum()); $user->zhixing();