Skip to content

Conversation

andot
Copy link
Contributor

@andot andot commented Jul 10, 2014

The old copy constructor of Php::Value does't work correctly when I put
a Php::Value with php reference into a std::vector, or use a reference
as a unordered_map key. for example:

Php::Value test_value_ctor(Php::Parameters &params) {
    int32_t count = params[0].size();
    std::vector<Php::Value> v;
    for (int32_t i = 0; i < count; ++i) {
        v.push_back(params[0][i]);
    }
    return v;
}

the test php file:

<?php
$a = array();
$a[] = &$a;
$a[] = "hello";
var_dump($a);
var_dump(test_value_ctor($a));
?>

Expected output is:

array(2) {
  [0]=>
  &array(2) {
    [0]=>
    *RECURSION*
    [1]=>
    string(5) "hello"
  }
  [1]=>
  string(5) "hello"
}
array(2) {
  [0]=>
  &array(2) {
    [0]=>
    *RECURSION*
    [1]=>
    string(5) "hello"
  }
  [1]=>
  string(5) "hello"
}

The actual output is:

array(2) {
  [0]=>
  &array(2) {
    [0]=>
    *RECURSION*
    [1]=>
    string(5) "hello"
  }
  [1]=>
  string(5) "hello"
}
array(2) {
  [0]=>
  array(2) {
    [0]=>
    &array(2) {
      [0]=>
      *RECURSION*
      [1]=>
      string(5) "hello"
    }
    [1]=>
    string(5) "hello"
  }
  [1]=>
  string(5) "hello"
}

This patch fixed it.

The old copy constructor of Php::Value does't work correctly when I put
a Php::Value with php reference into a std::vector, or use a reference
as a unordered_map key. for example:

```
Php::Value test_value_ctor(Php::Parameters &params) {
int32_t count = params[0].size();
std::vector<Php::Value> v;
for (int32_t i = 0; i < count; ++i) {
v.push_back(params[0][i]);
}
return v;
}
```

the test php file:
```
<?php
$a = array();
$a[] = &$a;
$a[] = "hello";
var_dump($a);
var_dump(test_value_ctor($a));
?>
```

Expected output is:
```
array(2) {
[0]=>
&array(2) {
[0]=>
*RECURSION*
[1]=>
string(5) "hello"
}
[1]=>
string(5) "hello"
}
array(2) {
[0]=>
&array(2) {
[0]=>
*RECURSION*
[1]=>
string(5) "hello"
}
[1]=>
string(5) "hello"
}
```

The actual output is:
```
array(2) {
[0]=>
&array(2) {
[0]=>
*RECURSION*
[1]=>
string(5) "hello"
}
[1]=>
string(5) "hello"
}
array(2) {
[0]=>
array(2) {
[0]=>
&array(2) {
[0]=>
*RECURSION*
[1]=>
string(5) "hello"
}
[1]=>
string(5) "hello"
}
[1]=>
string(5) "hello"
}
```

This patch fixed it.
@andot andot closed this Jul 10, 2014
@andot andot deleted the valuector branch July 10, 2014 08:33
@andot andot restored the valuector branch July 10, 2014 08:35
@andot andot reopened this Jul 10, 2014
The old implementation of move operator will break the iterator when the
array include the reference. (#115#issuecomment-48591931), this patch
fixed it.
@sjinks
Copy link
Contributor

sjinks commented Dec 23, 2016

This has been fixed in master (tested on 13685ba)

sjinks added a commit to sjinks/PHP-CPP that referenced this pull request Dec 23, 2016
@ghost
Copy link

ghost commented Dec 29, 2016

Apparantly this is already solved.

@ghost ghost closed this Dec 29, 2016
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants