문제

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

도움이 되었습니까?

해결책

$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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top