(代码缩写为清晰) 我有一个父类,DetailCollection,带有子类 KeycodeTracker: class DetailCollection { private $ aODetails; private function setDetail(& $ oDetail,$ bEcho = false){ $ this-> aODetails [] = $ oDetail; if($ bEcho){echo(count(" DetCol"。$ this-> aODetails。"< BR> ;")); } } } 类KeycodeTracker扩展DetailCollection { 私函数setDetail(& $ oDetail){ DetailCollection :: setDetail($ oDetail,true); echo(count(" KeyTrk"。$ this-> aODetails。"< ; BR>")); } } DetailCollection有一个名为setDetail的方法,它接受一个对象 通过引用传递并将其存储在数组中。这在 另一个覆盖DetailCollection的setDetail的子类中工作正常,但是 KeycodeTracker使用对原始类的调用而不起作用 - $ this-> aODetails中没有元素。 这与通过引用覆盖传递有什么关系 方法办法?或者我只是我自己新手的受害者? 谢谢你偷看! 泰勒I have what may be a bug, or may be a misunderstanding on how pass byreference and class inheritance works in PHP. Since I''m relativelynew to PHP, I''m hoping for a little outside help to shed some light onthis!(code abbreviated for clarity)I have a parent class, DetailCollection, with a child classKeycodeTracker:class DetailCollection{private $aODetails;private function setDetail(&$oDetail, $bEcho=false) {$this->aODetails[] =$oDetail;if($bEcho) { echo(count("DetCol".$this->aODetails."<BR>")); }}}class KeycodeTracker extends DetailCollection{private function setDetail(&$oDetail) {DetailCollection::setDetail($oDetail, true);echo(count("KeyTrk".$this->aODetails."<BR>"));}}DetailCollection has a method called setDetail, which takes an objectpassed by reference and stashes it in an array. This works fine inanother child class that overrides DetailCollection''s setDetail, butKeycodeTracker uses a call to the original class and does not work -there are no elements in $this->aODetails.Does this have anything to do with overriding a pass by referencemethod in some way? Or am I just a victim of my own newbieness here?Thanks for taking a peek!Tyler推荐答案 aODetails; 私人函数setDetail(&aODetails;private function setDetail(& oDetail, bEcho = false){bEcho=false) { 这篇关于PHP5和类继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-10 08:59