资源通过引用传递

When copying one resource to another, you're actually creating a reference to the original resource, this is not an actual copy.

将一个资源复制到另一个资源时,实际上是在创建对原始资源的引用,这不是实际的副本。

This is illustrated by the following example:

以下示例说明了这一点:


echo '<pre>';
// create an image resource
$image = imagecreate(100, 100);


// print the resource
var_dump($image);
// the above prints "resource(30) of type (gd)"

// create a copy 
// (actually creating a reference, 
// although =& is not implicitly used)
$copy = $image;

// print the reference
var_dump($copy);

// the above prints "resource(30) of type (gd)", same as before

// destroy the image resource
imagedestroy($image);

// this prints "resource(30) of type (Unknown)"
// so the image was destroyed
var_dump($image);

// this also prints "resource(30) of type (Unknown)"
// meaning that the reference points to a destroyed image
var_dump($copy);


echo '</pre>';

        
        

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/resources-passed-by-reference/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值