You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
463 B

<?php
/**
* 也就是说php中对象赋值,其实是引用
*/
class ClassA{
public $var=1;
}
$a=new ClassA;
$b=$a; //赋值后,$a,$b只是标识符不一样,其实指向了同样的内容
$b->var=2;
echo $a->var.PHP_EOL;
$c=new ClassA;
$d=&$c; //引用
$d->var=2;
echo $c->var.PHP_EOL;
$e=new ClassA;
function func($obj){
$obj->var=2;
}
func($e);
echo $e->var;
?>