Home arrow PHP arrow Page 3 - Using the .NET Assembly in PHP

Using the .NET Assembly in PHP

Using the power of COM interop, you can write code in VB.Net or C# and use it in PHP, VB6, or any other language that can access COM. In this article Jayesh shows us how.

Author Info:
By: Jayesh Jain
Rating: 4 stars4 stars4 stars4 stars4 stars / 46
October 15, 2002
  1. · Using the .NET Assembly in PHP
  2. · Creating an Assembly
  3. · Creating the PHP File
  4. · Conclusion

print this article

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:

Our PHP script 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

Unregistering the type library

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.

Removing the assembly from the GAC
blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials