查看: 670|回复: 1
|
PHP 新手问题。。 &$variable
[复制链接]
|
|
- array_walk ($words, array($this, '_prune'), &$words);
复制代码
请问$words前的 "&" 符号是做么的?? |
|
|
|
|
|
|
|
发表于 4-2-2007 07:09 PM
|
显示全部楼层
原帖由 kenyi 于 4-2-2007 06:32 PM 发表
array_walk ($words, array($this, '_prune'), &$words);
请问$words前的 "&" 符号是做么的??
这个是referenced object的意思。
例如:
- class foo {
- var $name;
- function setName($n){
- $this->name = $n;
- }
- }
- function namingFoo($foo){
- $foo->setName("bar");
- }
- function namingFooReferenced(&$foo){
- $foo->setName("bar");
- }
- $foo = new foo();
- $foo->setName("foo");
- namingFoo($foo);
- echo $foo->name; //output 'foo'
- namingFooReferenced($foo);
- echo $foo->name; //output 'bar'
复制代码
PHP5开始就直接pass argument as referenced object了,所以学PHP5的话就不用担心这个。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|