php.net |  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
Votes:2
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: csaba at alum dot mit dot edu
New email:
PHP Version: OS:

 

 [2007-11-13 11:49 UTC] csaba at alum dot mit dot edu
Description:
------------
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:
---------------
<?php
$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

or 

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 http://php.net/com_print_typeinfo)

Csaba Gabor from Vienna

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

Patches

Pull Requests

History

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

$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-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 17:01:28 2024 UTC