开发者

Explore a COM Object in PHP

What would be t开发者_开发百科he proper way to explode a COM object for debugging? I have a 3rd party function that returns a multilevel object. The documentation is non existant, so I'd like to be able to echo everything out of the object or debug it in Komodo IDE.

Komodo just says Object and nothing else. Maybe convert to array?

I know some of the existing options such as $com->Status, but there are more variables returned that I'd like to know what they are.


You can use com_print_typeinfo() instead of var_dump(). This should work for COM, VARIANT and DOTNET objects. The output looks similar to this:

class IFile { /* GUID={C7C3F5A4-88A3-11D0-ABCB-00A0C90FFFC0} */

// some PHP-COM internal stuff ...

 /* DISPID=1610612736 */
 function QueryInterface(
  /* VT_PTR [26] [in] --> ? [29]  */ &$riid,
  /* VT_PTR [26] [out] --> VT_PTR [26]  */ &$ppvObj 
  )
 {
 }
 /* DISPID=1610612737 */
 /* VT_UI4 [19] */
 function AddRef(
  )
 {
 }

// ...
 /* DISPID=1610678275 */
 function Invoke(
  /* VT_I4 [3] [in] */ $dispidMember,
  /* VT_PTR [26] [in] --> ? [29]  */ &$riid,
  /* VT_UI4 [19] [in] */ $lcid,
  /* VT_UI2 [18] [in] */ $wFlags,
  /* VT_PTR [26] [in] --> ? [29]  */ &$pdispparams,
  /* VT_PTR [26] [out] --> VT_VARIANT [12]  */ &$pvarResult,
  /* VT_PTR [26] [out] --> ? [29]  */ &$pexcepinfo,
  /* VT_PTR [26] [out] --> VT_UINT [23]  */ &$puArgErr 
  )
 {
 }

// properties and methods of the COM object
// ...

 /* DISPID=1001 */
 /* VT_BSTR [8] */
 /* Short name */
 var $ShortName;

 /* DISPID=1004 */
 /* VT_PTR [26] */
 /* Get drive that contains file */
 var $Drive;

 /* DISPID=1005 */
 /* VT_PTR [26] */
 /* Get folder that contains file */
 var $ParentFolder;


// ...

 /* DISPID=1204 */
 function Move(
  /* VT_BSTR [8] [in] */ $Destination 
  )
 {
  /* Move this file */
 }
 /* DISPID=1100 */
 /* VT_PTR [26] */
 function OpenAsTextStream(
  /* ? [29] [in] */ $IOMode,
  /* ? [29] [in] */ $Format 
  )
 {
  /* Open a file as a TextStream */
 }
}


It is weird that var_dump didn't work.

But you could try with other of php reflection tools.

Reflection Class:

<?php
Reflection::export(new ReflectionClass(get_class($data)));
?>

Or you could try with the get_class_methods:

<?php
  print_r(get_class_methods($data));
?>

or get_object_vars to see its fields:

<?php
  print_r(get_object_vars($data));
?>

Hope this helps.


The native var_dump() does not crash for COM objects.

The extension xdebug, replaces the native var_debug() function and does not support COM objects.

The solution would be to deactivate the overriding of the function var_dump() by xdebug by adding xdebug.overload_var_dump=off to php.ini.

The related bug in xdebug bug tracker

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜