Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106910 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8649 invoked from network); 9 Sep 2019 08:28:42 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 9 Sep 2019 08:28:42 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id D757F2CC1BE for ; Sun, 8 Sep 2019 23:03:46 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_MED,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.0.0.0/16 X-Spam-Virus: No Received: from mail.sensational.ch (mail.sensational.ch [IPv6:2001:8a8:6004:0:dead:beef:0:1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Sun, 8 Sep 2019 23:03:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=bZWdbbF0lHG8Cikdlt8spHmHCCuwfJWSOD/cvuQ6M5E=; b=APLA7vc4pn4e6tYI521aVW4LvsVGqL1paqewxR4nAWvcPFsIpj+R7AQfnmYA5ZmV/d q0ZBFUvxF1v1gbS/JQvPfchjkoUnaILf2jLizI00TR29PugieouOuye7/xDH85U7bLiP xi0g+PJ3AZM9jAjWgyeN8se7yuGxWCWAP2SH6e1t7wwYU72JZIcUJlbNAMpDvrLH0rUl ArYJxVe8SnlSMyzGYYx5BT4jCzwF7lRrnYZ9d6AUjvbMUyuByy6Cg9JHTiDfEWQb70J0 uUC2y7xjH2OUG771rIMoz7isW7Vr9JaOPVBH/ijSe3JgFvd3OYGOS9drHTdwofqF7eoY HhpQ== X-Gm-Message-State: APjAAAU5ZgOTdL80VXHDefSh/zWE2UF74/SwN8GcJd2vZT4ZtqBMtVKS u/ShlmB4zYWxQhYJV5MhafKZeCC3zGyug+GHsX03J0zfLJdFyfdsdPTHlif7LoC2RAVRv+YrzG0 Y2hvobPM9iMipwf+oqFwI3Yv2DQiB4rvveT6w5x33IpvF X-Received: by 2002:a05:600c:22c9:: with SMTP id 9mr17761343wmg.133.1568009023383; Sun, 08 Sep 2019 23:03:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ+bDbptDqnlTWf7yEcgsQKLCx1mD/twpxv8y+3+cjpJQt0MqXvBhAabzChfaLOAOlsf+522NeMItYye3/seg= X-Received: by 2002:a05:600c:22c9:: with SMTP id 9mr17761325wmg.133.1568009023066; Sun, 08 Sep 2019 23:03:43 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 9 Sep 2019 08:03:32 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000d326a00592188c95" X-SA-Do-Not-Run: Yes X-Envelope-From: Subject: FFI extension / NULL-Checks From: phofstetter@sensational.ch (Philip Hofstetter) --000000000000d326a00592188c95 Content-Type: text/plain; charset="UTF-8" Hello, (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? isset($err) $err[0] != null -> is always true, regardless of whether func as assigned an error or not isset($err->{0}) isset($err[0]) -> Cannot use object of type FFI\CData as array $err->{0} != NULL; -> FFI\Exception: NULL pointer dereference $err[0]; -> segfault I'm sure I must be doing something wrong, but I don't know what. Also, the documentation could do with an example on how to achieve the desired result and, TBH, I think some of the various attempts produce a somewhat unexpected output. Any comments? Philip var_dump(isset($r->{0})); -> Error: Cannot use object of type FFI\CData as array $a = '{0}'; var_dump(isset($r->$a)); -> Error: Cannot use object of type FFI\CData as array var_dump(isset($r[0])); var_dump($r[0]); --000000000000d326a00592188c95--