On 09.09.2019 at 08:03, Philip Hofstetter wrote:

> (I'm writing to the internals list because I don't think that at this
> point, FFI usage is wide-spread enough to get an opinion on other venues)
>
> maybe I'm just stupid, but I think there has been a slight oversight in the
> API design for the FFI interface.
>
> My problem is with functions that return a pointer to a struct as an out
> parameter.
>
> So in C, it would look like this:
>
> Error* err;
> func(&err);
>
> if (err != NULL){
>    do_error_handling();
> }
>
> If I translate this to PHP FFI, I would do
>
> $err = $ffi->new("Error*");
> $ffi->func(FFI::addr($err));
>
> if I `var_dump` $err, I do see a public {0} property be set to NULL or to
> actual error data.
>
> My issue is though: How do I check whether err* as been assgined to?

You could check FFI::addr($err)[0]:

  $err = $ffi->new("Error*");
  $perr = FFI::addr($err);
  $ffi->func($perr);
  var_dump(is_null($perr[0]));
  FFI::free($perr);

Not sure if it's supposed to require this indirection, though.

--
Christoph M. Becker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to