适配器模式
<?php //适配器模式 class tianqi { public static function show(){ $today = ['tep' => 28,'wind' =>7,'sun' => 'sunny']; return serialize($today); } } //适配器 class AdapterTianqi extends tianqi { public static function show(){ $today = unserialize(parent::show()); $today = json_encode($today); return $today; } } $tq = unserialize(tianqi::show()); echo '温度:' . $tq['tep'] . '<br />'; echo '风力:' . $tq['wind'] . '<br />'; echo 'sun:' . $tq['sun'] . '<br />'; echo '<br />php仿其他语言调用<br />'; //java,python通过适配器调用 $tq = AdapterTianqi::show(); $tq = json_decode($tq,true); echo '温度:' . $tq['tep'] . '<br />'; echo '风力:' . $tq['wind'] . '<br />'; echo 'sun:' . $tq['sun'] . '<br />';