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: 2019-10-21 11:10 UTC
From: asmqb7 at gmail dot com Assigned:
Status: Open Package: *Extensibility Functions
PHP Version: 7.4.0RC1 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jan 25 18:01:23 2021 UTC