<?php
/**
* 深入理解PHP对象赋值
*
* @author 50882007@qq.com
*/
class testAB {
public $a = "";
public $b = "";
}
/**
* 方法传值测试
*/
class testRefAb {
public static function printTestAB($abObj) {
$abObj->b = "is 5555";//更改内容
var_dump($abObj);
}
}
//对象赋值(对象是地址的赋值)
$a = new testAB;
$a->a = "dog";
$b = $a;
$b->b = "is 5";
var_dump($a);//被$b 修改了
testRefAb::printTestAB($a);
var_dump($a);//$a被更改了
unset($a);
var_dumb($b);//$b 也没有了
//对象克隆测试
$a = new testAB;
$a->a = "dog";
$b = clone $a;
$b->b = "is 5";
var_dump($a);
testRefAb::printTestAB($a);
//数组测试
$a = array("a" => "", "b" => "");
$a['a'] = "dog";
$b = $a;
$b['b'] = "is 8";
var_dump($a);
testRefAb::printTestAB($a);
/**
* 深入理解PHP对象赋值
*
* @author 50882007@qq.com
*/
class testAB {
public $a = "";
public $b = "";
}
/**
* 方法传值测试
*/
class testRefAb {
public static function printTestAB($abObj) {
$abObj->b = "is 5555";//更改内容
var_dump($abObj);
}
}
//对象赋值(对象是地址的赋值)
$a = new testAB;
$a->a = "dog";
$b = $a;
$b->b = "is 5";
var_dump($a);//被$b 修改了
testRefAb::printTestAB($a);
var_dump($a);//$a被更改了
unset($a);
var_dumb($b);//$b 也没有了
//对象克隆测试
$a = new testAB;
$a->a = "dog";
$b = clone $a;
$b->b = "is 5";
var_dump($a);
testRefAb::printTestAB($a);
//数组测试
$a = array("a" => "", "b" => "");
$a['a'] = "dog";
$b = $a;
$b['b'] = "is 8";
var_dump($a);
testRefAb::printTestAB($a);