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 Viennacom_print_typeinfo
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
com_print_typeinfo
Референца за `function.com-print-typeinfo.php` со подобрена типографија и навигација.
com_print_typeinfo
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
com_print_typeinfo — Испечатете PHP дефиниција на класа за интерфејс што може да се диспечира
= NULL
$variant, ?string $dispatch_interface = null, bool $display_sink = false): boolЦелта на оваа функција е да помогне во генерирањето на скелетна класа за употреба како приемник на настани. Можете исто така да ја користите за генерирање на испис на кој било COM објект, под услов тој да поддржува доволно од интерфејсите за интроспекција и да го знаете името на интерфејсот што сакате да го прикажете.
Параметри
variant-
variantтреба да биде или инстанца на COM објект, или да биде име на библиотека на типови (што ќе биде решено според правилата поставени во com_load_typelib()). dispatch_interface-
Име на
IDispatchинтерфејс потомок што сакате да го прикажете. display_sink-
Ако е поставено на
true, соодветниот интерфејс за приемник ќе биде прикажан наместо тоа.
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.
Види Исто така
- com_event_sink() - Поврзете настани од COM објект до PHP објект
- com_load_typelib() - Вчитува Typelib
Белешки од корисници 2 забелешки
In my particular version of PHP, the second and third arguments are not, in fact, optional.
Passing in '' for both, however, yielded a bucketful of information.
YMMV