Bug #66116 [NEW]: Cloning object leaving resource reference
| From: | joni2back at gmail dot com | Date: | Tue, 19 Nov 2013 11:47:11 +0000 |
| Subject: | Bug #66116 [NEW]: Cloning object leaving resource reference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-182822@lists.php.net to get a copy of this message | ||
From: joni2back at gmail dot com
Operating system: Debian 6
PHP version: Irrelevant
Package: Variables related
Bug Type: Bug
Bug description:Cloning object leaving resource reference
Description:
------------
When object is cloned and it have a property that handle resource
The resource is not cloned, remains the same of the previous instance
This could affect dependence resource options (for example setting curl
url in an instance will set all cloned instnaces, closing file, etc)
Test script:
---------------
<?php
class ResourceA
{
public $resource, $id;
function __construct()
{
//for example i use curl resource to change and view handler
options
$this->id = md5(rand());
$this->resource = curl_init();
curl_setopt($this->resource, CURLOPT_URL, $this->id);
}
}
class ResourceB extends ResourceA
{
}
/** ******************************************** **/
$resourceA = new ResourceA;
$resourceB = new ResourceB;
$resourceC = clone $resourceA;
//Setting an option to this resource shouldn't affect ResourceA resource
that was cloned
$resourceC->id = md5(rand());
curl_setopt($resourceC->resource, CURLOPT_URL, $resourceC->id);
print_r(array(
array($resourceA, 'RESOURCEPROP_'.curl_getinfo($resourceA->resource,
CURLINFO_EFFECTIVE_URL)),
array($resourceB, 'RESOURCEPROP_'.curl_getinfo($resourceB->resource,
CURLINFO_EFFECTIVE_URL)),
array($resourceC, 'RESOURCEPROP_'.curl_getinfo($resourceC->resource,
CURLINFO_EFFECTIVE_URL)),
));
######################OUTPUT#######################
Array
(
[0] => ResourceA Object
(
[resource] => Resource id #1
[id] => 934e1b0a64a6891959c68c254282d177
)
//This was affected by reference $resourceC->id =
md5(rand());
[1] => RESOURCEPROP_2188ba855d89b48713a0dc4fecb2c8a9
)
Array
(
[0] => ResourceB Object
(
[resource] => Resource id #2
[id] => f11b5e72957e4d173f1ae86f34dd7f63
)
[1] => RESOURCEPROP_f11b5e72957e4d173f1ae86f34dd7f63
)
Array
(
[0] => ResourceA Object
(
//The resource remains the same (is not Resource id #3)
[resource] => Resource id #1
//curl_setopt($resourceC->resource, CURLOPT_URL,
$resourceC->id);
[id] => 2188ba855d89b48713a0dc4fecb2c8a9
)
//$resourceC->id = md5(rand())
[1] => RESOURCEPROP_2188ba855d89b48713a0dc4fecb2c8a9
)
Expected result:
----------------
The resource should clone
$obj1->resource = Resource id #1
$obj2 = clone $obj
$obj2->resource = Resource id #2
Actual result:
--------------
The resource remains the same
$obj1->resource = Resource id #1
$obj2 = clone $obj
$obj2->resource = Resource id #1
--
Edit bug report at https://bugs.php.net/bug.php?id=66116&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66116&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66116&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66116&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66116&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66116&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66116&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66116&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66116&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66116&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66116&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66116&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66116&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66116&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66116&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66116&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66116&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66116&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66116&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66116&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66116&r=mysqlcfg