为您详解PHP开发工具的使用与分析_PHP
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了为您详解PHP开发工具的使用与分析_PHP,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6357字,纯文字阅读大概需要10分钟。
内容图文
![为您详解PHP开发工具的使用与分析_PHP](/upload/InfoBanner/zyjiaocheng/249/48f15911e092439183011f9178a8e222.jpg)
以下是引用片段: /* filename: SetGetTest.php comment on assignment by value and referrence assuming $var is a varialbe, its handle(pointer) is named as *var, and its content is named as @var the memory area of @var is referred by *var, if the *var is the same, then the memory areas are the same, so *var is just like a pointer. 1. when $var = $var1 @var copied from @var1, but in the different memory area, new *var assigned by the system, pointing to the memory area holding @var *var and *var1 are different 2. when $var =& $var1, *var assigned by *var1, and the @var is not assigned or copied, it is absolutely the same as @var1, and in the same memory area both *var and *var1 pointing to the memory area, that means they are the same. passing by referrence 3. function set1(&$s){ $var =& $s; } set1($var1) results: *var1 passing to the function, and *s is the same as *var1, then *var is the same as *s, the result is that *var is the same as *var1 and all the contents are the same obviously. 4. function set2(&$s){ $var = $s; } set2($var1) results: *var1 passing to the function, and *s is the same as *var1, but when $var = $s executes, from 1. we can see @var is the same as @s, but *var is different from *s, so @var and @s is not in the same memory area, while @s and @var1 is sharing the same memory area, also *var1 and *s are the same. 5. normal function return: function get(){ return $var1; } assuming the result is referred by a variable $result. then @result is copied from @var1 but *result is not the same as *var1 when $var = get(); first you get a variable $result, as I said above, @result is the same as @var1, but *result is different from *var1, and next $var = $result executes. As I said in 1., you can find, @var is the same as @result and the same as @var1, but *var is different from *result AND *var1; while $var =& get() just means: *var is the same as *result, so @var and @result are in the same memory area, but they are still different from those of $var1, both the memory area of @var1 and *var1, 6. returning by referrence function &get(){ return $var1; } there are two ways to get the result $var = get(); and $var =& get(); now I will tell the difference I. $var = get(); the *result is the same as *var1 and so @result and @var1 are the same. and then $var = $result executes, *var is not the same as *result, and also different from *var1, but their contents are the same. I. $var =& get(); the *result is the same as *var1 and so @result and @var1 are the same. and then $var =& $result executes, this means $var and $result are the same, both of @ and * */ // the test is the following function println($s = ""){ print "$s \n"; } class GetSetTest { var $var = null; function setByRef(&$arg){ $this->var =& $arg; } function passByRef(&$arg){ $this->var = $arg; } function setByVal($arg){ $this->var = $arg; } function &getByRef(){ return $this->var; } function getByVal(){ return $this->var; } } $o = new GetSetTest; println("============ setByRef getByRef ============="); println("-----------------Before change----------------"); $in = "before change"; $o->setByRef($in); $outByVal = $o->getByRef(); $outByRef =& $o->getByRef(); println("\$in: ".$in); println("\$outByVal: ".$outByVal); println("\$outByRef: ".$outByRef); println("\$this->var: ".$o->var); println("-----------------After change-----------------"); $in = "after change"; println("\$in: ".$in); println("\$outByVal: ".$outByVal); println("\$outByRef: ".$outByRef); println("\$this->var: ".$o->var); println(); println("============ setByRef getByVal ============="); println("-----------------Before change----------------"); $in = "before change"; $o->setByRef($in); $outByVal = $o->getByVal(); $outByRef =& $o->getByVal(); println("\$in: ".$in); println("\$outByVal: ".$outByVal); println("\$outByRef: ".$outByRef); println("\$this->var: ".$o->var); println("-----------------After change-----------------"); $in = "after change"; println("\$in: ".$in); println("\$outByVal: ".$outByVal); println("\$outByRef: ".$outByRef); println("\$this->var: ".$o->var); println(); println("============ passByRef getByVal ============="); println("-----------------Before change----------------"); $in = "before change"; $o->passByRef($in); $outByVal = $o->getByVal(); $outByRef =& $o->getByVal(); println("\$in: ".$in); println("\$outByVal: ".$outByVal); println("\$outByRef: ".$outByRef); println("\$this->var: ".$o->var); println("-----------------After change-----------------"); $in = "after change"; println("\$in: ".$in); println("\$outByVal: ".$outByVal); println("\$outByRef: ".$outByRef); println("\$this->var: ".$o->var); println(); /* 以下输出结果是我(夜猫子)擅自编辑添加的,主要是为后来人查看方便加在这里,越肉代庖,向longnetpro致歉 输出结果: ============ setByRef getByRef ============= -----------------Before change---------------- $in: before change $outByVal: before change $outByRef: before change $this->var: before change -----------------After change----------------- $in: after change $outByVal: before change $outByRef: after change $this->var: after change ============ setByRef getByVal ============= -----------------Before change---------------- $in: before change $outByVal: before change $outByRef: before change $this->var: before change -----------------After change----------------- $in: after change $outByVal: before change $outByRef: before change $this->var: after change ============ passByRef getByVal ============= -----------------Before change---------------- $in: before change $outByVal: before change $outByRef: before change $this->var: before change -----------------After change----------------- $in: after change $outByVal: before change $outByRef: before change $this->var: after change */ ?> |
内容总结
以上是互联网集市为您收集整理的为您详解PHP开发工具的使用与分析_PHP全部内容,希望文章能够帮你解决为您详解PHP开发工具的使用与分析_PHP所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。