Home  >  Article  >  Backend Development  >  php 种 构造方法

php 种 构造方法

WBOY
WBOYOriginal
2016-06-13 10:56:44747browse

php 类 构造方法
php 类的构造方法传递数组,取出来是NULL。为什么???

class Excel{
  var $re;
  function __construct($re){
  $this->exc=$re;
  }
  function get(){
  return $this->re;
  }

}
?>

============
require_once("./b.php");
$tem=array(1,4,7,8);

$t = new Excel($tem);

$ff=$t->get();

var_dump($ff);======================NULL
?>



------解决方案--------------------
class Excel{
var $re;
function __construct($re){
$this->exc=$re;
}
function get(){
return $this->re;
}
}
属性名都不对应,如何能得到正确结果?
------解决方案--------------------
构造函数内 你都没给 属性 re 赋值
$this->exc=$re;
改成
$this->re=$re;
------解决方案--------------------
属性名不一致,$this->re与$this->exc 
 它俩统一一下
LZ大意了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn