欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP 观察者模式_PHP教程

程序员文章站 2022-04-25 11:13:36
...

 Observed   
     ->_observers = 
      attach(SplObserver ->_observers->attach(
      detach(SplObserver ->_observers->detach(
     (->_observers  ->showMessage(
      setName(->_name = ->
      ->
      setAge(->age = (->_observers  ->showAge(->_name,->
 Observer 
      showMessage(SplSubject  = ->(==='admin' '您好, ',,'欢迎您进入管理后台
' "你好, '' 你已经被添加到了用户列表
" update(SplSubject showAge(, " 的年龄是: ')" = Observed(); = Observer(); ->attach(); ->setName('张三'); notify(); * 通过调用 $this->notify()就会调用 $observer->showMessage($this)方法, * 即每个观察者对象的 showMessage($obj)方法; ->setName('admin'->setAge(24);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440273.htmlTechArticleObserved -_observers = attach(SplObserver -_observers-attach( detach(SplObserver -_observers-detach( ( -_observers -showMessage( setName( -_name = - - setAge( -age = ( -_observers...