为什么不需要取消引用它

为什么不需要取消引用它

本文介绍了如果$ a =& $ b是通过引用分配的,为什么不需要取消引用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这么多地方,包括坚果壳中的PHP一书,p。 80,它说:


$ a =& $ b#设置$ a来引用$ b


如果$ a参考$ b,那么当你可以说$ b = 1时,你真的不可能

说$ a = 1.你需要说*($ a)= 1,如C或C ++。引用

必须与解除引用相结合,并且PHP没有进行解除引用,所以为什么它首先调用引用?

(不要告诉我PHP会自动取消引用......因为它真的会很奇怪)


我认为在PHP组中,人们说参考表示别名。


所以我的问题是


1)如果是参考,为什么你不需要将它取消引用为上面提到的



2)实际上有两个引用方法(如我之前的帖子

主题)。一个是$ obj1 = $ obj2,它的工作原理与Java相同,

Python和Ruby(也许在Perl中也是如此?)。另一种行为是$ a

=& $ b和它是不同的,为什么它仍然被称为引用?

为什么有两个不同的行为使用相同的名称

" reference"?为什么不拨打$ a =& $ b别名,并调用$ obj1 = $ obj2

复制引用? ($ obj2引用一个对象,所以复制这个

引用$ obj2)


在某种程度上,如果C,C ++,Java,Python,Ruby ,所有使用单词引用

表示$ obj1 = $ obj2,如果PHP想要不同并调用aliase作为

" reference",与世界其他地方不同,我可以尊重

。但问题是,为什么称之为引用然后让其他行为
行为$ obj1 = $ obj2哪个不同,并且AGAIN称之为引用?

so many places, including the book PHP in a Nutshell, p. 80, it says:

$a =& $b # set $a to reference $b

if $a reference $b, then while you can say $b =1, you can''t really
say $a = 1. you need to say *($a) = 1 as in C or C++. Referencing
must be coupled with dereferencing, and PHP is not doing the
dereferencing, so why is it call referencing in the first place?
(don''t tell me PHP automatically dereference... as it will be really
weird).

and i think in the PHP group, people say "reference" to mean "alias".

So my questions are

1) If it is by reference, why don''t you need to dereference it as
mentioned above?

2) There are actually two "reference" methods (as in my previous post
topic). One is $obj1 = $obj2, and it works the same as in Java,
Python, and Ruby (maybe in Perl too?). The other behavior is the $a
=& $b and it is different, and why is it still called "reference"?
Why having two different behaviors use the same name which is
"reference"? Why not call $a =& $b aliasing, and call $obj1 = $obj2
copying the reference? ($obj2 reference an object, and so copy this
reference to $obj2)

In a way, if C, C++, Java, Python, Ruby, all use the word reference to
mean $obj1 = $obj2, if PHP wants to be different and call "aliase" as
"reference", and different from the rest of the world, I can respect
that. But the thing is, why call it reference and then have the other
behavior $obj1 = $obj2 which is different, and AGAIN call it reference?

推荐答案




这篇关于如果$ a =& $ b是通过引用分配的,为什么不需要取消引用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:44