如题所述
第1个回答 2017-08-22
写一个 你看看。
<?php
class test{
public $conn;
function __construct($M=NULL){
if($M != NULL) $this->conn= $M;
else {
$this->conn= 'ddddd';
}
}
function getconn(){
return $this->conn;
}
}
$aa = 111;
$obj = new test($aa);
$get1 = $obj->getconn();
$obj2 = new test();
$get2 = $obj2->getconn();
echo '<br>有传参数='.$get1.'<br>未传参数='.$get2;
?>
<?php
class test{
public $conn;
function __construct($M=NULL){
if($M != NULL) $this->conn= $M;
else {
$this->conn= 'ddddd';
}
}
function getconn(){
return $this->conn;
}
}
$aa = 111;
$obj = new test($aa);
$get1 = $obj->getconn();
$obj2 = new test();
$get2 = $obj2->getconn();
echo '<br>有传参数='.$get1.'<br>未传参数='.$get2;
?>
第2个回答 2017-09-01
其实很多OOP语言都差不多,对于对象的传递是引用,如果你不想对象被引用,那你需要把对象clone一个新对象。 字串与数值的是值传递。
第3个回答 2020-03-06
搜一下:php中构造函数的参数是接口类型,在实例化一个对象时这个参数怎么传