脚本宝典收集整理的这篇文章主要介绍了PHP重写方法规则,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
那么为什么我能用其他参数和数量替换方法呢?这是合法的还是将来会引发错误,或者我只是遗漏了什么?
PHP版本5.5.11
class PEt { PRotected $_name; protected $_status = 'None'; protected $_petLocation = 'who kNows'; // Want to replace this function protected function playing($game = 'ball') { $this->_status = $this->_type . ' is playing ' . $game; return '<br>' . $this->_name . ' started to play a ' . $game; } public function getPetStatus() { return '<br>Status: ' . $this->_status; } } class Cat extends Pet { function __construct() { $this->_type = 'Cat'; echo 'test: The ' . $this->_type . ' was born '; } // Replacing wITh this one public function playing($gameType = 'chess',$location = 'backyard') { $this->_status = 'playing ' . $gameType . ' in the ' . $location; return '<br>' . $this->_type . ' started to play a ' . $gameType . ' in the ' . $location; } } $cat = new Cat('Billy'); echo $cat->getPetStatus(); echo $cat->playing(); echo $cat->getPetStatus();
这将输出:
以上是脚本宝典为你收集整理的PHP重写方法规则全部内容,希望文章能够帮你解决PHP重写方法规则所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。