Using the .NET Assembly in PHP - Creating the PHP File
(Page 3 of 4 )
Create a text file with the following content and save the file as phpnet.php in c:\inetpub\wwwroot folder (or your webserver http root folder):
<?
$MyObj = new COM ("phpclass.HealthRecord.patient");
$MyObj->lmp = "05/08/2002";
echo "LMP : $MyObj->lmp";
echo "<BR>EDD : $MyObj->edd";
?> Examining the Code Firstly, we create a COM object for the object that we just installed and registered. COM interop makes the .NET assembly look like COM objects, and we can use the same syntax as we use to create typical COM objects in PHP:
$MyObj = new COM ("phpclass.HealthRecord.patient"); Next, we set the lmp property to a valid date, which will then be used to calculate the edd:
$MyObj->lmp = "05/08/2002"; Now we output the LMP property in a human-readable date format. We also output the calculated EDD property to the browser:
echo "LMP : $MyObj->lmp";
echo "<BR>EDD : $MyObj->edd"; Running the Code Open your favorite browser and surf to http://localhost/phpnet.php to see the PHP file in action:
Using COM Interop in VB6 You could use the same steps as shown above to create a COM wrapper around the .NET assembly and use it in VB6. Here's the VB6 code for your reference:
Set MyObj = CreateObject("phpclass.HealthRecord.patient")
MyObj.lmp = "05/08/2002"
MsgBox "LMP : " & MyObj.lmp
MsgBox "EDD : " & MyObj.edd Unregistering the Type Library To unregister the type library, run regasm with the /unregister switch and specify the assembly path:
regasm /unregister c:/tgol/phpclass/bin/phpclass.dll
Removing the Assembly from Global Assembly Cache To remove the assembly from the GAC, run gacutil with the /u switch and specify the assembly name, like this:
gacutil /u phpclass Don't specify the path to the assembly and also don't add the .dll extension to the assembly name.

Next: Conclusion >>
More PHP Articles
More By Jayesh Jain