在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<?php class Base{ private $_m = array(); public function attachBehavior($behaviorObj){ $behaviorObj->attach($this); $this->_m[] = $behaviorObj; } public function __call($method,$param){ foreach($this->_m as $obj){ if(method_exists($obj,$method)){ call_user_func(array($obj,$method),$param); } } } } class Behavior{ protected $scope; public function attach($scope){ $this->scope = $scope; } } class BehaviorTest extends Behavior{ public function prints($param){ print_r($this->scope); } } class TestObj extends Base{ public function __construct(){ $this->name = 'test'; $this->age = 20; } } $behaviorTestIns = new BehaviorTest(); $baseIns = new TestObj(); $baseIns->attachBehavior($behaviorTestIns); $baseIns->prints(); ?>
|
2022-08-17
2022-11-06
2022-08-17
2022-07-18
2022-07-18
请发表评论