I do some hairy Outlook and Exchange programming. Not by choice, but by force — I have users that won’t give up Outlook for any reason, and they want it to interoperate with our PHP-based database.
I usually do my Outlook scripting in VBScript, since Outlook has a snazzy COM API (COM = “Component Object Model” = Microsoft’s way to make other programs, like Outlook, do stuff from code). However, I recently put together a command line scripting environment for PHP (see this post), and I really didn’t want my scripts spread across two languages.
PHP started supporting COM back in version 4, but I had heard it was buggy and annoying, with PHP functions just to set values on COM objects and such (“com_get,” “com_set,” etc.). But, being a glutton for punishment, I gave it try anyway.
Oh my, how things have changed.
As of this writing, COM support in PHP is so good, I’d venture that you could take a VBScript, stick dollar signs in front of your variables, replace “.” with “->”, put some semi-colons in, and it would run. Getting a COM object is like this:
$outlookInstance = new COM("Outlook.Application");
From there, you can call methods and properties exactly as if it was a native PHP object.
$nameSpace = $outlookInstance->GetNamespace("MAPI"); $folder = $nameSpace->GetFolderFromID([...]);
The only problem I ran into was that COM didn’t like PHP nulls. Calling strval solved that problem.
I’m pretty smitten with this whole scenario. PHP is simply a more capable language than VBScript, and being able to access COM so easily means I can write better scripts faster in PHP. With this, I think I’ve jettisoned VBScript forever. Very cool.