|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43275 get_class problem with COM objects
Submitted: 2007-11-13 11:49 UTC Modified: 2015-04-07 17:47 UTC
Avg. Score:2.0 ± 1.0
Reproduced:0 of 1 (0.0%)
From: csaba at alum dot mit dot edu Assigned:
Status: Not a bug Package: COM related
PHP Version: 5.2.5 OS: Win XP Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
31 + 41 = ?
Subscribe to this entry?

 [2007-11-13 11:49 UTC] csaba at alum dot mit dot edu
Anomaly: get_class returns "com" with InternetExplorer and Excel COM objects. But with other COM objects it returns "variant".  This seems inconsistent to me.

Reproduce code:
$ie = new COM("InternetExplorer.Application");
$ie->Navigate2 ("about:blank");
while ($ie->readyState<4) {
  com_message_pump(200); }
$doc = $ie->document;
$body = $doc->body;
$excel = new COM("Excel.Application");
$wb = $excel->workbooks->add();

$aCom = array(ie, doc, body, excel, wb);
foreach ($aCom as $comObj)
  print "$comObj: " . gettype($$comObj) .
        " => " . get_class($$comObj) . "\n";

Expected result:
ie: com => IWebBrowser2
doc: com => HTMLDocument
body: com => HTMLBody
excel: com => Application
wb: com => Workbook


ie: object => com:IWebBrowser2
doc: object => com:HTMLDocument
body: object => com:HTMLBody
excel: object => com:Application
wb: object => com:Workbook

or at a bare minimum

ie: object => com
doc: object => com
body: object => com
excel: object => com
wb: object => com

To be specific:  I am advocating that gettype() on a com object return "com".  More importantly, get_class on a COM object should return consistently:  either always "com", or "com:" followed by the typename, or (my preference) simply the typename.

Typename here refers to the VB typename function (or use my typeName function found on

Csaba Gabor from Vienna

Actual result:
ie: object => com
doc: object => variant
body: object => variant
excel: object => com
wb: object => variant


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-07 17:47 UTC]
-Status: Open +Status: Not a bug
 [2015-04-07 17:47 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

$ie and $excel are instances of COM (they have been created by `new
COM`), whereas the other objects are instances of Variant (they
have been returned by the automation servers and wrapped by PHP's
com extension).

Changing the behavior of gettype() and get_class() would be
inconsistent with PHP's view, and would furthermore be a massive BC
break. However, as you have demonstrated with the typeName()
function, retrieving the class of the automation object itself can
easily be implemented in userland.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 06:05:53 2022 UTC