Introduction
The built-in COM function of PHP4 is really attractive to people who program in win32 environment. At present, there are not many documents about this. This article uses three examples (MS office 2000, Excel, Adobe Distiller) to explain how to program with COM in PHP4. Microsoft has been developing COM technology with different names for many years. In this article, OLE, OLE automation, ActiveX, and COM are the same: Use a piece of encapsulated code to implement some functions for a windows application. The COM of PHP4 establishes a connection with the object (instantiate the object) and then uses the methods and attributes in it.
If you want to re-develop these examples, the following is my Configuration:
Windows 98-MS Office 2000
Apache 1.3.9 Windows
PHP4.02 Dev (08-20-00) Running as CGI
COM mark in PHP4
Let's start with the COM function in PHP4. To instantiate a control, you need a "new" operator and the "OLE identifier" of the object ":
COM is a class name reserved by PHP4. It passes $ identifier to the constructor. Now we have an instantiated control that can be easily referenced by OOP technology. For example:
[Object]-> [method1]-> [method2]->...-> [property];?>
That's easy!
If such a reference is not allowed (sometimes PHP syntax errors are caused when the attribute name or value contains special characters such as dots or parentheses), PHP4 COM also provides two functions:
Bool com_set (class com_object, string property name, string property_value );
Mixed com_get (class com_object, string property_name );
?>
Finally, PHP4 also supports DCOM to create an instance of objects on a remote computer.
$ Instance = new COM (string "Component name", string "remote_server_address ");
?>
All the above are functions. No other functions need to be remembered!
Note: PHP may support using DCOM on Unix in the future.
Identifier, method, and attribute
The identifier is a string similar to the following:
MS Word: "Word. Application" or "Word. Application.9"
MS Excel: "Excel. Application" or "Excel. Sheet"
ADOBE Acrobat: "Exch. application" or "sharedistiller. sharedistiller"
As indicated by the last identifier, not all object names are obvious. If you do not have a VBA document, you can view the HKEY_CLASSES_ROOT folder of the Registry: Under the extension list, you can see the name of the application, and the CLSID sub-folder contains the available COM identifier.
The application should provide documents on the methods and attributes of COM. For example, in Office 2000, open a program, use the shortcut key to open the VB editor, and then use Open the object editor. Enter the name of a method or attribute, select a member, and select help to get the description of the member. You can also access MSDN. An Excel example is: http://msdn.microsoft.com/library/officedev/off2000/xltocobjectmodelapplication.htm
Translation: http://www.phpbuilder.com/columns/alain20001003.php3