PHP在类没有__construct()时定义默认值


PHP defines default values when the class have not __construct()?

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

在这种情况下,$name$mat得到零值?如果我在最后一行使用回显$a->getName(),我就没有返回。有人知道吗?

$name$mat获得null值(它们未定义)。你得不到任何回报,因为根本就没有什么可回报的。它们是null

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

输出如下:http://ideone.com/lcuSNB