php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78544 FFI\CData et al do not support ReflectionObject nor get_object_vars()
Submitted: 2019-09-15 13:43 UTC Modified: 2021-09-16 21:29 UTC
From: asmqb7 at gmail dot com Assigned:
Status: Open Package: FFI (PECL)
PHP Version: 7.4.0RC1 OS: Linux
Private report: No CVE-ID: None
 [2019-09-15 13:43 UTC] asmqb7 at gmail dot com
Description:
------------
I fully expect this is already known and in the to-implement queue; perhaps this bug could be use to track progress.

FFI\CData does not support reflection-based analysis, rendering virtually all third-party data inspection tools (ie alternatives to print_r() and var_dump()) useless (unless there are some cool obscure bits I'm missing - I sadly doubt this, but hey, just in case...).

One related thing of possibly-particular note is that var_dump() and print_r() are able to access an informative type label like "FFI\CData:struct test", while ReflectionObject and get_object_vars() only seem to have access to an effectively meaningless "FFI\CData". Hopefully this is just because reflection-specific capabilities are not yet implemented(?).

Thanks very much in advance whenever this gets fixed! :)

Test script:
---------------
<?php

$ffi = FFI::cdef(' struct test { int dummy; }; ');

$test = $ffi->new('struct test');

$r = new ReflectionObject($test);

print "getShortName: "; var_dump($r->getShortName());
print "getMethods: "; var_dump($r->getMethods());
print "__toString: "; var_dump($r->__toString());

print "getDefaultProperties: "; var_dump($r->getDefaultProperties());
print "getProperties: "; var_dump($r->getProperties());

print "get_object_vars: "; var_dump(get_object_vars($r));

print "var_dump(): "; var_dump($test);

print "print_r(): "; print_r($test);


Expected result:
----------------
For the output made available through var_dump() et al to be accessible via ReflectionObject

Actual result:
--------------
getShortName: string(5) "CData"
getMethods: array(0) {
}
__toString: <<<boring, snipped>>>
getDefaultProperties: array(0) {
}
getProperties: array(0) {
}
get_object_vars: array(1) {
  ["name"]=>
  string(9) "FFI\CData"
}
var_dump(): object(FFI\CData:struct test)#2 (1) {
  ["dummy"]=>
  int(0)
}
print_r(): FFI\CData:struct test Object
(
    [dummy] => 0
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-16 21:29 UTC] cmb@php.net
-Package: *Extensibility Functions +Package: FFI
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 20:01:27 2024 UTC