php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67100 Array copy and reference problem in pecl module.
Submitted: 2014-04-21 08:26 UTC Modified: 2018-02-28 17:21 UTC
Votes:9
Avg. Score:4.6 ± 0.7
Reproduced:8 of 9 (88.9%)
Same Version:6 (75.0%)
Same OS:5 (62.5%)
From: greevex at gmail dot com Assigned:
Status: Open Package: mongo (PECL)
PHP Version: 5.5.11 OS: Scientific Linux 6.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: greevex at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-21 08:26 UTC] greevex at gmail dot com
Description:
------------
php-pecl-mongo version 1.4.5

I don't really think that it's problem in mongo pecl module, because this is problem  of an inside PHP Engine (optimizations for passing variables by reference before it's changed).

Test script:
---------------
function prepare() {
    return [
        'key' => 'test1',
        'create' => time(),
        'update' => 0,
        'value' => 0
    ];
}
function save($array2) {
    $db = (new Mongo('localhost'))->selectDB('test');
    $collection = $db->selectCollection('test');
    // array2: new field `_id` would be added, insert requesting param by reference
    $collection->insert($array2);
    // `some` field only in array1, but `_id` field in both arrays
    return $array2;
}
$array1 = prepare();
$array2 = save($array1);
// array1: add `some` field to array1
$array1['some'] = true;
var_dump(isset($array1['_id']), isset($array2['_id']), isset($array1['some']), isset($array2['some']));

Expected result:
----------------
bool(false)
bool(true)
bool(true)
bool(false)

Actual result:
--------------
bool(true)
bool(true)
bool(true)
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-28 17:21 UTC] cmb@php.net
-Package: Scripting Engine problem +Package: mongo
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 08:01:29 2024 UTC