PHP对象赋值测试帮助理解
2016-02-23 18:35
615 查看
<?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);
相关文章推荐
- phpstorm中的数据库
- NTP服务器搭建
- &nbsp;vsftp配置大全---超完整版…
- laravel在*nix 下安装及创建项目
- smtp发送邮件记得结尾发送"\r\n.\r\n"
- ajax无刷新删除、复制 THINKPHP
- php函数和语法结构
- yii2 增加新的目录结构
- php如何发起POST DELETE GET POST 请求
- PHP curl 实现RESTful PUT DELETE 实例
- PHP之设计模式(工厂、单例)
- Ubuntu下启动pptp失败问题
- ubuntu 14.04 部署vsftpd
- php中Mail_mimeDecode无法读取foxmail等eml文件正文问题
- editplus快捷键大全
- phpcms /api/phpsso.php SQL Injection Vul
- 实现RTP协议的H.264视频传输系统
- Thinkphp中的内置标签用法
- PHP设计模式-单例模式
- fsl 环境搭建与tftp nfs samba配置 分包压缩