Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment to element in child array in C++ replaced the whole child array #7

Open
hcngac opened this issue Jan 25, 2017 · 0 comments

Comments

@hcngac
Copy link

hcngac commented Jan 25, 2017

in C++,

Php::Array PhpArray;
Php::Array PhpSubArray({"a","b","c","d"});
PhpArray["1111"]["2222"] = PhpSubArray;
Php::call("var_dump", PhpArray);
PhpSubArray[0] = "X";
Php::call("var_dump", PhpArray);
PhpArray["1111"]["2222"][0] = "X";
Php::call("var_dump", PhpArray);

would result in

array(1) {
  [1111]=>
  array(1) {
    [2222]=>
    array(4) {
      [0]=>
      string(1) "a"
      [1]=>
      string(1) "b"
      [2]=>
      string(1) "c"
      [3]=>
      string(1) "d"
    }
  }
}
array(1) {
  [1111]=>
  array(1) {
    [2222]=>
    array(4) {
      [0]=>
      string(1) "a"
      [1]=>
      string(1) "b"
      [2]=>
      string(1) "c"
      [3]=>
      string(1) "d"
    }
  }
}
array(1) {
  [1111]=>
  array(1) {
    [2222]=>
    array(1) {
      [0]=>
      string(1) "X"
    }
  }
}

while in PHP,

$PhpArray = Array();
$PhpSubArray = Array('A','B','C','D');
$PhpArray['1111']['2222'] = $PhpSubArray;
var_dump($PhpArray);
$PhpSubArray[0] = 'X';
var_dump($PhpArray);
$PhpArray['1111']['2222'][0] = 'X';
var_dump($PhpArray);

result in

array(1) {
  [1111]=>
  array(1) {
    [2222]=>
    array(4) {
      [0]=>
      string(1) "A"
      [1]=>
      string(1) "B"
      [2]=>
      string(1) "C"
      [3]=>
      string(1) "D"
    }
  }
}
array(1) {
  [1111]=>
  array(1) {
    [2222]=>
    array(4) {
      [0]=>
      string(1) "A"
      [1]=>
      string(1) "B"
      [2]=>
      string(1) "C"
      [3]=>
      string(1) "D"
    }
  }
}
array(1) {
  [1111]=>
  array(1) {
    [2222]=>
    array(4) {
      [0]=>
      string(1) "X"
      [1]=>
      string(1) "B"
      [2]=>
      string(1) "C"
      [3]=>
      string(1) "D"
    }
  }
}

Is it normal behavior or is it a bug? Thank you!

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

No branches or pull requests

1 participant