PHP引用的用法

来源:互联网 发布:mac解压软件知乎 编辑:程序博客网 时间:2024/05/16 15:51

midir (01-Mar-2009 03:44)

Here is a good magazine article (PDF format) that explains the internals of PHP's reference mechanism in detail:http://derickrethans.nl/files/phparch-php-variables-article.pdf

It should explain some of the odd behavior PHP sometimes seems to exhibit, as well as why you can't create "references to references" (unlike in C++), and why you should never attempt to use references to speed up passing of large strings or arrays (it will make no difference, or it will slow things down).

It was written for PHP 4 but it still applies. The only difference is in how PHP 5 handles objects: passing object variables by value only copies an internal pointer to the object. Objects in PHP 5 are only ever duplicated if you explicitly use the clone keyword.

源自:PHP手册 语言参考/引用的解释 评论