<?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