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

Exception on two dimensional array assignment #376

Open
TianBo-Timothy opened this issue May 11, 2018 · 1 comment
Open

Exception on two dimensional array assignment #376

TianBo-Timothy opened this issue May 11, 2018 · 1 comment

Comments

@TianBo-Timothy
Copy link

I am having a problem when assigning a value to a two-dimensional array while writing a PHP extension with PHPCPP library.

The extension works fine with PHPCPP5 + PHP5, but fails with PHPCPP7 + PHP7 (both on ubuntu 16.04). When works with PHPCPP7, I get a fatal error with message:

PHP Fatal error: Cannot make a variable undefined in /path/to/my/php/code.php

The function in the extension looks like:

Php::Value foo(Php::Parameters & params)
{
    Php::Value test;
    test[2][0] = 100;
    return test;
}

I tried to change Php::Value to Php::Array, the same error is produced. If I change test[2][0] = 100; to test["a"][0] = 100;, then there is no error. However, this is not what I want.

The stack trace is as follows:

-- stack trace --
  /path/to/my/extension.so : Php::Value::setType(Php::Type) &+0x182
  /path/to/my/extension.so : Php::Value::Value(Php::Type)+0x30
  /path/to/my/extension.so : Php::Value::get(int) const+0x73
  /path/to/my/extension.so : Php::HashMember<int>::value() const+0x49
  /path/to/my/extension.so : Php::HashMember<int>::set(int, Php::Value const&)+0x36
  /path/to/my/extension.so : Php::HashMember<int>::operator=(Php::Value const&)+0x3a
  /path/to/my/extension.so : foo(Php::Parameters&)+0x95
  /path/to/my/extension.so : void Php::ZendCallable::invoke<&(foo(Php::Parameters&))>(_zend_execute_data*, _zval_struct*)+0x66
  php : ()+0x2e1456
  php : execute_ex()+0x1b

I am not sure if it is due to a newly introduced bug or there is a mistake I made in my code, please have a look. Thanks!

@TianBo-Timothy
Copy link
Author

To those who are having the same problem, the following workaround works:

Php::Value foo(Php::Parameters & params)
{
    Php::Value test;
    Php::Array v;
    v[0] = 100;
    test[2] = v;
    return test;
}

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