CakeFest 2024: The Official CakePHP Conference

com_print_typeinfo

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

com_print_typeinfoディスパッチインターフェイスのために、PHP のクラス定義を出力する

説明

com_print_typeinfo(variant|string $variant, ?string $dispatch_interface = null, bool $display_sink = false): bool

この関数の目的は、イベントシンクに使用するスケルトンクラスの作成を支援することです。 もし 対象の COM オブジェクトが イントロスペクションのインターフェイスを十分サポートしており、 表示したいインターフェイスの名前をあなたが知っている場合、 その COM オブジェクトのダンプを生成するのにも使えます。

パラメータ

variant

variant は、COM オブジェクトのインスタンスか あるいはタイプライブラリの名前 (com_load_typelib() の規則にしたがって名前解決されます) のいずれかです。

dispatch_interface

結果を表示したいインターフェイスで、 このインターフェイスは IDispatch を継承したものです。

display_sink

true の場合、対応するシンクインターフェイスが代わりに表示されます。

戻り値

成功した場合に true を、失敗した場合に false を返します。

参考

add a note

User Contributed Notes 2 notes

up
2
csaba at alum dot mit dot edu
19 years ago
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
up
-1
Richard Lynch
17 years ago
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
To Top