|
|
|
|
| Tutorial |
.bool com_set(class com_object, string property_name, string
property_value)
Assigns a value for a property on the COM object instantiated in com_object.
Aliases for this function are com_propset() and com_propput(). Returns true on
success and false on error.
n mixed com_get(class com_object, string property_name)
Returns the value of a property on the COM object instantiated in com_object.
Alias for this function is com_propget(). Returns the property’s value on success
and false on error.
The source code in Listing 5.4 shows the basic use of the COM feature. It creates an
instance of the COM class using the Softwing.EDConverter component, a freely available
currency-conversion utility.Then the member method Triangulate() is invoked and
the returned result displayed. It can’t get much easier…
Listing 5.4 A basic COM example.
$amount = 1000; // Amount to be converted
$curr_from = “DEM”; // ISO currency symbol of original currency
$curr_to = “ITL”; // Symbol of the target currency
// Instantiate new COM object
$conv = new COM(“Softwing.EDConverter”) or die(“Unable to instantiate
➥Euro-Converter”);
// Execute a component method on the COM object’s instance
$ret = $conv->Triangulate(10000, “ITL”, “DEM”) or die(“Exception triggered by
➥Triangulate() on line “.__LINE__);
// Print the result
print($ret);
196 Chapter 5 Basic Web Application Strategies
In PHP 3.0, you can’t use the COM class; instead, you need to use the com_load(),
com_invoke(), com_set(), and com_get() functions. Our example would look like
Listing 5.5.
To create an instance of a DCOM component on a remote system, pass the
hostname as second argument to the constructor. For example:
$comp = new COM(“My.Component”, “remote.server.com”);
Listing 5.5 A basic COM example with PHP version 3.0.
$amount = 1000; // Amount to be converted
$curr_from = “DEM”; // ISO currency symbol of original currency
$curr_to = “ITL”; // Symbol of the target currency
// Instantiate new COM object
$conv = com_load(“Softwing.EDConverter”) or die(“Unable to instantiate
➥Euro-Converter”);
// Execute a component method on the COM object’s instance
$ret = com_invoke($conv, “Triangulate”, “10000”, “ITL”, “DEM”) or
➥die(“Exception triggered by Triangulate() on line “.__LINE__);
// Print the result
print($ret);
The syntax of these functions (that are not available in PHP 4.0) is as follows:
n int com_load(string component_name)
Instantiates a COM component and creates a reference to it.The returned integer
value must be used in the following com_*() calls. Returns false and throws a
warning if an error occurs.
n mixed com_invoke(int com_identifier, string function_name[, mixed
argument1[,...]])
Invokes a COM component’s method and returns the method’s return value.The
first argument of the function is a valid COM identifier as created with
com_load().The second argument must be the name of a component method.
As optional third and following arguments, you can specify arguments for the
invoked method.This function returns false on error.
197 Three-Tier Applications
n bool com_set(int com_identifier, string property_name, string
property_value)
Assigns a value for a property on the COM object instantiated in com_object.
Aliases for this function are com_propset() and com_propput(). Returns true on
success and false on error.
n mixed com_get(int com_identifier, string property_name)
Returns the value of a property on the COM object instantiated in com_object.
Alias for this function is com_propget(). Returns the property’s value on success
and false on error.
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|