note 49989 added to function.com-print-typeinfo
| From: | csaba at alum dot mit dot edu | Date: | Mon, 14 Feb 2005 20:49:25 +0000 |
| Subject: | note 49989 added to function.com-print-typeinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85029@lists.php.net to get a copy of this message | ||
com_print_typeinfo is really useful if you're trying to figure out what properties and methods
you have access to. For example, I might do:
<?php
$oExplorer = new COM("Shell.Application");
com_print_typeinfo($oExplorer);
?>
The first line shows me the class of the object (what VBScript calls 'typename'), in my
case IShellDispatch4. It's frequently the case that if you plunk that in as the second
argument to com_print_typeinfo, you get way more methods/properties coming back. Thus:
<?php
$oExplorer = new COM("Shell.Application");
com_print_typeinfo($oExplorer, "IShellDispatch4");
?>
Furthermore, you might get additional functions listed if you try lower number suffixes (or not).
At any rate, it would be useful for PHP to have a typename function like VBScript does. For
example, if you iterate through the Windows of $oExplorer you get both IE and Explorer windows and
typename is the easy way to differentiate between them. Here's what I'm using:
<?php
function typeName($objCOM) {
if (empty($objCOM)) return "no COM object";
if (gettype($objCOM)!="object") return "not a COM object";
ob_start();
com_print_typeinfo($objCOM);
$typeInfo = ob_get_contents();
ob_end_clean();
$pattern = "/^\\s*class (.*) \\{/";
if (!($matchCnt = preg_match($pattern, $typeInfo, $aMatch))) return "Not found";
return $aMatch[1];
}
?>
Csaba Gabor from Vienna
----
Manual Page -- http://www.php.net/manual/en/function.com-print-typeinfo.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49989
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49989&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49989&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49989&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49989&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49989&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49989&report=yes
Search -- http://master.php.net/manage/user-notes.php