简体   繁体   English

PHP指针与引用

[英]PHP pointers vs references

In PHP, what is the difference between using a pointer such as: 在PHP中,使用指针之间的区别如下:

function foo( $var )
{
    $var = 3;
}

$a = 0;
foo( &$a );

And reference: 并参考:

function foo( &$var )
{
    $var = 3;
}

$a = 0;
foo( $a );

They both modify the value of the original variable, but are they represented differently internally? 它们都修改了原始变量的值,但它们是否在内部表示不同?

In PHP, there are no pointers, only references. 在PHP中,没有指针,只有引用。 Your examples demonstrate pass by reference 您的示例演示通过引用传递

The difference between your code snippets is only in syntax, where the first syntax is now deprecated. 代码片段之间的区别仅在于语法,现在不推荐使用第一种语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM