<?php //装饰器模式:不改变数据结构,只作一些细微的修改 class Words{ public $my_txt; public function __construct($txt){ $this->my_txt = $txt; } } class DecoratorWords{ public function Decorator(Words $word){ $word->my_txt = strtoupper($word->my_txt); return $word; } } $docorator_obj = new DecoratorWords(); echo $docorator_obj->Decorator(new Words("hello world!"))->my_txt;