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

Passing string values by reference back to PHP #451

Open
Justas-S opened this issue Sep 6, 2020 · 1 comment
Open

Passing string values by reference back to PHP #451

Justas-S opened this issue Sep 6, 2020 · 1 comment

Comments

@Justas-S
Copy link

Justas-S commented Sep 6, 2020

I am aware that using Php::ByRef in the method argument definition, values can be passed by reference and then cast to char * to avoid copying. Is it possible to achieve the same in the opposite direction: return a char * reference back to PHP?

One way I could see achieving this is passing another variable from PHP to use as the return value. Something like:

<?php

$out = null;
method(in, &out);
void method (Php::Parameters &params)
{
   const char *input = params[0];
   // Process it somehow to produce a new result
   memcpy(params[1].buffer(), new_value, new_value_size);
}

I am not certain if this would work, but a more PHP-friendly solution is still preferred.

@EmielBruijntjes
Copy link
Member

EmielBruijntjes commented Sep 6, 2020

I dont know by heart, can you experiment with this yourself? Maybe if you do something like this:

void method (Php::Parameters &params)
{
    // maybe this works?
    params[0] = "a new value";

    // or this?
    params[0] = std::string("a new value");
}

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