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

Value::operator=(Value &&value) does not work when this is a reference #411

Open
jonmcclung opened this issue Apr 4, 2019 · 1 comment

Comments

@jonmcclung
Copy link

jonmcclung commented Apr 4, 2019

The following code produces an unexpected result:

#include <phpcpp.h>

void withMoveConstructor(Php::Parameters &params) {
  params[0] = Php::Value("withMoveConstructor worked");
}

void withCopyConstructor(Php::Parameters &params) {
  Php::Value temp = Php::Value("withCopyConstructor worked");
  params[0] = temp;
}

extern "C" {
    PHPCPP_EXPORT void *get_module() {
        static Php::Extension extension("extension", "1.0");
        extension.add<withMoveConstructor>("withMoveConstructor",{
            Php::ByRef("value", Php::Type::String)
        });
        extension.add<withCopyConstructor>("withCopyConstructor",{
            Php::ByRef("value", Php::Type::String)
        });
        return extension;
    }
}
<?php

$a = "withMoveConstructor failed";
$b = "withCopyConstructor failed";

withMoveConstructor($a);
withCopyConstructor($b);

echo "$a, $b";

return;

Expected output:
withMoveConstructor worked, withCopyConstructor worked

Actual output:
withMoveConstructor failed, withCopyConstructor worked

I expect this is related to #300. Is there any chance this can be fixed? In this example it simply failed to set the value but I have run into a lot of cases where it produces a segmentation fault instead.

@scorninpc
Copy link

scorninpc commented May 31, 2019

You always should store the value to Php::Value, and store Php::Vaue into z_val. Notice: c are typed, so param are refenced by z_val, but param[0] are pointed to hashtable of zend engine.

In other words, param[0] aren't reference variable

sorry if my english are confuse

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

2 participants