douhuangjian9627 2014-05-15 00:59
浏览 86
已采纳

当类没有__construct()时,PHP定义默认值?

<?php
class Alumn {
  private $name;
  private $mat;
  } 
  function getName()
  {
    return $this->name;
  }
  function getMat()
  {
    return $this->mat;
  }
}
 $a = new Alumn();
?>

In this case $name and $mat get zero value? If I use a echo $a->getName() in the last line I have not return. Anyone knows it? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzong5473 2014-05-15 01:07
    关注

    $name and $mat get null values (they're not defined). You get nothing returned because there is nothing to return...they're null.

    if($a->getName() == NULL)
        print "Alumn->name is NULL";
    if($a->getMat() == NULL)
        print "Alumn->mat is NULL";
    

    See the following for output: http://ideone.com/lcuSNB

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置