最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
References and Aliases are Different Mechanisms (z
时间:2022-07-02 10:30:22 编辑:袖梨 来源:一聚教程网
References and Aliases are Different Mechanisms
Author: zkarakaya
Date 14/03/2001
Aliasing and Referencing are completely different mechanisms in PHP.
If you are Java or C++ programmer, you must be careful when using
Objects created on run-time.
What value be the output of this program code. Many programmer will
say "20", but this is not correct. Output is 10. Why? Because we have
created an instance of MyClass type on the right hand side of assignment
operator, and gave an initial value of 10. In the constructor of MyClass,
we have send the memory location of that newly created instance to another
Author: zkarakaya
Date 14/03/2001
Aliasing and Referencing are completely different mechanisms in PHP.
If you are Java or C++ programmer, you must be careful when using
Objects created on run-time.
Lets see an example;
class MyClass{
var $myData;
var $outManager;
cfunction MyClass($p){
$this->myData=$p;
$this->outManager = new MyOutManager($this);
}
cfunction display(){
$this->outManager->display();
}
}
class MyOutManager{
var $refObj;
cfunction MyOutManager(&$obj){
$this->refObj = &$obj;
}
cfunction display(){
echo $this->refObj->myData;
}
}
$myvar = new MyClass(10);
$myvar->myData = 20;
$myvar->display();
?>
What value be the output of this program code. Many programmer will
say "20", but this is not correct. Output is 10. Why? Because we have
created an instance of MyClass type on the right hand side of assignment
operator, and gave an initial value of 10. In the constructor of MyClass,
we have send the memory location of that newly created instance to another
相关文章
- Tplink企业版路由器WiFi名称的默认设置介绍(Tplink企业版路由器WiFi名称的默认设置是什么) 09-06
- Tplink路由器灯常亮无法上网的原因分析(如何解决Tplink路由器灯常亮无法上网的问题) 09-06
- Tplink千兆企业级路由器自动重启的作用和优势介绍(如何设置Tplink千兆企业级路由器自动重启功能) 09-06
- 一根天线的tplink路由器有哪些(一根天线的Tplink路由器的特点和优势介绍) 09-06
- tplink路由器外网访问不了nas(Tplink路由器外网访问NAS的原因分析) 09-06
- Tplink无法搜到路由器的原因分析(如何解决Tplink无法搜到路由器的问题) 09-06