面向对象问题 输出没结果

ccav5 发布于 2012/07/08 22:15
阅读 130
收藏 0
PHP
name = $name; } abstract function fire(); } class NastyBoss{ //员工数组 private $employees = array(); function addEmployee( Employee $employee ){ $employees[] = $employee; // print_r($employees); } function projectFails(){ // print_r($this->employees); if(count($this->employees) ){ $emp = array_pop($this->employees); $emp->fire(); } } } class wellconnected extends Employee{ function fire(){ print "{$this->name} :I'll call my layer"; } } class minion extends Employee{ function fire(){ print "{$this->name} :I'll call my layer"; } } class cluedup extends Employee{ function fire(){ print "{$this->name} :I'll call my layer"; } } $boss = new NastyBoss(); $boss->addEmployee(Employee::recruit("hary")); $boss->addEmployee(Employee::recruit("pot")); //var_dump($boss); $boss->projectFails(); ?> 为什么 project 方法中 count的结果为0 而 addEmplyee中的 emplyees数组有打印出来
加载中
0
jeffsui
jeffsui
哎,一看到这样的代码,我就无语,难道你不知道选择代码格式吗?
0
寻找爱玩Tom
寻找爱玩Tom
看到这样的代码,我都不像解答了,懒得看,楼主重新整理吧,养成好的习惯
ccav5
ccav5
恩,新手昨天不知道有‘插入代码’功能,重发过了,问题已解决
返回顶部
顶部