这是一个基于PHP重载的有趣oo解决方案:
class thousand_printer { public function __construct() { $this->print1(); } public function __call($method,$_) { $count = str_replace('print','',$method); echo "$count "; $this->{"print" . ++$count}(); } public function print1000() { echo "1000\n"; } } new thousand_printer;
我很高兴我的解决方案如此受欢迎.这是一个略微改进,提供了一些模块化:
class printer { public function __construct() { $this->print1(); } public function __call($method,$method); echo "$count "; $this->{"print" . ++$count}(); } } class thousand_printer extends printer { public function print1001() {} } new thousand_printer;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。