tomfmason Posted January 10, 2007 Share Posted January 10, 2007 In this particular case I know all of the functions available to me. However, this will not always be the case. Most applications that support COM have documentation but it is sometimes difficult to understand.. Also, not all of the functions and methods can be used with php. So I started to look at reflection. It seems to be exactly what I want. But being the seasoned newb that I am, I can't quite get it work with COM.. I have tried with other classes and it works fine..Here is an example use..(forgive the mess)[code=php:0]$com = new COM("powerpoint.application") or die('Unable to instantiate PowerPoint');Reflection::export(new ReflectionClass($com));$com->quit();[/code]This returns nothing.. The output[b]EDIT[/b]removed the [nobbc][code][/nobbc] blocks because of the annoying italic text..[hr][nobbc]Class [ class com extends variant ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [0] { } }[/nobbc][hr]As you can see it returns nothing.. It shows that there are not any methods or properties of $com.. Maybe I am just going the wrong way about this.. Is there another way that I can do this or am I completely off track.. Any suggestions would be great.Thanks, Tom Quote Link to comment Share on other sites More sharing options...
.josh Posted January 10, 2007 Share Posted January 10, 2007 Man, I've been researching and experimenting with this for hours and nothing seems to work. I can tell you some things I've learned about this stuff though:[code=php:0]$com = new COM("powerpoint.application") or die('Unable to instantiate PowerPoint');[/code]This returns an overloaded object. If you don't know what that means, basically it means that if you make a call to an undefined property or method, you can assign a "wildcard" method or property to handle it. Now, this line here:[code=php:0]Reflection::export(new ReflectionClass($com));[/code]as you probably know, calls a method in the reflection class, passing as its argument an instantiated reflectionclass object (which actually extends the reflection class, btw.) Perhaps an easier way to read it would be like this:[code=php:0]$blah = new ReflectionClass($com);Reflection::export($blah);[/code] or better yet, since ReflectionClass extends Reflection, you could do this:[code=php:0]$blah = new ReflectionClass($com);$blah->export($blah);[/code]Now, as to your problem of it not showing $com's info: The class you actually want to be using is ReflectionObject, not ReflectionClass. ReflectionClass reverse-engineers a class, but $com is an (overloaded) object. But guess what? Every time I tried to do this:[code=php:0]$com = new COM("powerpoint.application") or die('Unable to instantiate PowerPoint');Reflection::export(new ReflectionObject($com));[/code]Apache crashed on me. Don't know why or how or what. It just kapooted. According to the manual, it should work. My research into why it was crashing has come up blank. I then tried this alternative:[code=php:0]$com = new COM("powerpoint.application") or die('Unable to instantiate PowerPoint');// get properties of objectprint_r(get_object_vars($com));// get methods of a class: manual says you // can use an object instead of a class name for thisprint_r(get_class_methods($com)); [/code]But still no dice!The manual also claims that you can loop through a COM object's stuff with a foreach or a while loop, like so:[code=php:0]$com = new COM("powerpoint.application");foreach ($com as $obj) { echo $obj->Name . "<br />";} // or...$com = new COM("powerpoint.application");while ($obj = $com->Next()) { echo $obj->Name . "<br />";} [/code]still no dice! I still get all kinds of errors thrown at me! I know that the $com object is indeed call powerpoint (well actually, I used word.application, but whatever). For instance, I can do this:[code=php:0]echo $com->Version; [/code]and it will print out the version. I can also go to my task manager and it will indeed show a Word process going on. (btw: don't forget to do $com->Quit(); I conveniently forgot that line in the beginning and I had like 30 instances of Word running before I realized it, LoL). I have searched and searched and searched and I'm starting to come to the conclusion that retrieving a list of properties/methods of a COM object is impossible with php. You have to know ahead of time that info. I don't see why you shouldn't be able to get it, but I just can't find anything. I suspect that it may have to do with the fact that it's an overloaded object. I can kind of sort of picture in my head how it's kind of sort of impossible to come up with a list of methods/properties for something that kind of sort of has variable/infinite methods/properties, due to it being overloaded. Does that make sense? I think it might somehow be throwing itself into some kind of infinite loop and well..that's why apache crashes. But I can't confirm it. It's just my half-baked theory. LoL, I want to get to the bottom of this. I have learned a ton about COM and Reflection from this venture :) Quote Link to comment Share on other sites More sharing options...
tomfmason Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks alot CV.. I have php 5.2.0 and for the time being I have apache running as a service.. Well I looked in the event viewer I see that it is phpt2.dll that brings apache down.. I will do some more research and see what i can come up with..Thanks again,Tom Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 Hey, guys, if either of you come up with something, please let me know. I'm extremely interested in what you find out. I've recently been doing a little playing with Reflection in PHP5 myself, so I'll keep tabs on this thread ;) Quote Link to comment Share on other sites More sharing options...
tomfmason Posted January 10, 2007 Author Share Posted January 10, 2007 Well reflection it's self is rather simple.. Well maybe not.. :)It works fine with most other objects/classes/functions but when it comes to com it kills apache.. So if you are not using COM then it should be fine.. Quote Link to comment Share on other sites More sharing options...
Destruction Posted January 10, 2007 Share Posted January 10, 2007 This likely doesn't help but several posts, including User Comments in the PHP Manual, state that it cannot be done with the COM class. Functions such as get_class_methods() also do not work with COM to my understanding. If I find anything that contradicts this I'll let you know.Dest Quote Link to comment Share on other sites More sharing options...
.josh Posted January 10, 2007 Share Posted January 10, 2007 Really? I didn't come across any posts that said that. Granted, I was researching into the wee hours of the night on this, so I may have missed a sentence or 2... I'll go back and re-read the posts. Or if you feel up to it, possibly you could provide some quotes or something? Quote Link to comment Share on other sites More sharing options...
tomfmason Posted January 10, 2007 Author Share Posted January 10, 2007 Well I have done a little more research on the subject.. It seems that reflection is not going to work in this case.. Everyone that I speak to seems to think that this is not possible with reflection.Now back to one of CV's examples, I tried this..[code=php:0]<?php$com = new COM("powerpoint.application") or die('Unable to instantiate PowerPoint');$pres = $com->Presentations;$mess = '';foreach ($pres as $obj) { $mess .= $obj->Name . "<br />";}echo (strlen($mess) > 0)? $mess : 'mess is empty.. :(';$com->quit();?>[/code]Well I have gotten somewhere.. I can loop through presentations without an error.. That is were most of the objects/methods that are needed are located. However, this always echos [b]mess is empty.. :([/b]So I guess that I am starting to get somewhere.. I guess I will continue to research.Tom Quote Link to comment Share on other sites More sharing options...
448191 Posted January 18, 2007 Share Posted January 18, 2007 I'd wish I could help you with this one, but I all I can really tell you is that appearantly some MS component, probably powerpoint itself, crashes when trying to use Reflection.I use Kaspersky Internet security, and when trying use reflection on a Powerpoint COM object it reveals the system is trying to send an error report to Microsoft. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.