README 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. This is the new php5 COM module.
  2. It is not 100% backwards compatible with PHP 4 ext/com, but you should not miss
  3. the "features" that have not been retained.
  4. This module exposes 3 classes: variant, com and dotnet(*).
  5. com and dotnet classes are descendants of the variant class; the only
  6. difference between the three are their constructors. Once instantiated, the
  7. module doesn't make a distinction between them.
  8. COM errrors are mapped to exceptions; you should protect your COM code using
  9. the try..catch construct if you want to be able to handle error conditions.
  10. Be warned that due to the way the ZE2 currently works, exceptions are only
  11. "armed" at the time they are detected, but do not "detonate" until the end of
  12. the statement. So, code like this:
  13. $obj->foo[43]->bar();
  14. Where the foo[43] access triggers an exception will continue to call the bar()
  15. method on a null object and cause a fatal php error.
  16. Default properties and array access:
  17. $obj = new COM("...");
  18. $obj[1]->foo();
  19. The code above will use the type information for the object to determine its
  20. default property and then access it. In PHP 4, it was hard-coded to use the
  21. "Items" member, which was wrong.
  22. The default property will also be used by the casting support to determine the
  23. value for the object.
  24. Variants:
  25. This implementation of COM takes a simpler approach than the PHP 4 version;
  26. we only map a few native types to COM and vice-versa, leaving the more complex
  27. things as variants. This allows greater consistency of data when passing
  28. parameters to and from COM objects (no data will be lost). In addition, a
  29. large number of the variant API has been mapped to PHP space so that you can
  30. use it for working with the special variant decimal, currency and date time
  31. types. This could be used as a replacement for the bcmath extension, for
  32. example.
  33. You can use the new object casting hook to for a php-native representation of
  34. a variant object:
  35. $a = new variant(4);
  36. $b = new variant(6);
  37. $c = variant_add($a, $b);
  38. echo $c; // outputs 10 as a string, instead of Object
  39. Sample Script:
  40. <?php
  41. $word = new COM("word.application");
  42. print "Loaded Word, version {$word->Version}\n";
  43. $word->Visible = 1;
  44. $word->Documents->Add();
  45. $word->Selection->TypeText("This is a test...");
  46. $word->Documents[1]->SaveAs("Useless test.doc");
  47. $word->Quit();
  48. ?>
  49. TODO:
  50. - documentation
  51. * dotnet support requires that you have the mscoree.h header from the .net sdk
  52. when you build the module.