duancongjue9202 2014-05-01 22:08
浏览 87
已采纳

PHP中的抽象类可以有默认方法吗?

I've most certainly got something very basic wrong here.

Here is the code that is part of my Abstract Class:

private $outarray = null;

public function add_to_array($ahref, $docname, $description) {
  $row = array('ahref' => $ahref, 'docname' => $docname, 'description' => $description);
  if (!isset($this->outarray)) {
    $this->outarray = array();
  }
  array_push($this->outArray, $row);
}

screenshot

When I step through the code, though, the outArray remains null. It is never created and never populated.

I'm still green with PHP, but this help doc seems to leave me believing that this is OK to do:

http://www.php.net/manual/en/language.oop5.abstract.php

...particularly where they are declaring the Common method printOut() that performs some action.

I've got 5 elements I am trying to populate outArray with, but each of the 5 times I circle into this function, I come out with outArray being NULL.

  • 写回答

2条回答 默认 最新

  • dongshen2903 2014-05-01 22:13
    关注

    Variables are case sensitive. You have in one place $this->outarray and in array_push you have $this->outArray

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)