PHP to a COM object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    #1

    PHP to a COM object

    Hello,

    I'm trying to use a (remote) COM object from a PHP script (4.4, server has
    apache2 win32).

    The basics seem to work : I instantiate the COM object ($o = new COM"..."),
    then I use two of the objects methods to authenticate. In the meantime a
    property called "ProjectConnect ed", passes from 0 to 1. So I think the
    object is correctly instanciated and the connection works.

    But now, I'm doing a var_dump on my object and I get this :
    object(COM)(1) {
    [0]=resource(127) of type (COM)
    }

    Arg. I don't understand this and the PHP manual doesnt help either. I would
    have expected to get a list of methods/properties. At least the two I use to
    authenticate.

    var_dump ($obj[0]) returns null.


    Could someone explain me more about this ?

    Thanks,
    --
    Alex
    [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
    autres jeux de role.



  • Jerry Stuckle

    #2
    Re: PHP to a COM object

    Alex wrote:
    Hello,
    >
    I'm trying to use a (remote) COM object from a PHP script (4.4, server has
    apache2 win32).
    >
    The basics seem to work : I instantiate the COM object ($o = new COM"..."),
    then I use two of the objects methods to authenticate. In the meantime a
    property called "ProjectConnect ed", passes from 0 to 1. So I think the
    object is correctly instanciated and the connection works.
    >
    But now, I'm doing a var_dump on my object and I get this :
    object(COM)(1) {
    [0]=resource(127) of type (COM)
    }
    >
    Arg. I don't understand this and the PHP manual doesnt help either. I would
    have expected to get a list of methods/properties. At least the two I use to
    authenticate.
    >
    var_dump ($obj[0]) returns null.
    >
    >
    Could someone explain me more about this ?
    >
    Thanks,
    This is correct; this is an external resource in PHP.

    AFAIK, the only way you can get a list of properties and methods of a
    COM object is if the COM object itself supports such a request.

    And the resource object in PHP isn't an array, which is why you get null
    when you try to dump $obj[0].

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Csaba Gabor

      #3
      Re: PHP to a COM object

      On Nov 14, 10:56 am, "Alex" <d_key...@hotma il.comwrote:
      ....
      I'm trying to use a (remote) COM object from a PHP script (4.4, server has
      apache2 win32).
      >
      The basics seem to work : I instantiate the COM object ($o = new COM"..."),
      ....
      But now, I'm doing a var_dump on my object and I get this :
      object(COM)(1) {
      [0]=resource(127) of type (COM)
      }
      >
      Arg. I don't understand this and the PHP manual doesnt help either. I would
      have expected to get a list of methods/properties. At least the two I use to
      authenticate.
      Check out:
      Print out a PHP class definition for a dispatchable interface


      Csaba Gabor from Vienna

      Comment

      • Alex

        #4
        Re: PHP to a COM object

        ....
        subsequent question : gettype returns "object". Shouldnt it return
        "resource" ?

        As a matter of fact get_resource_ty pe returns nothing at all, nor does
        com_print_typei nfo .

        What can I deduct ? simply that the object just doesnt support some requests
        allowing to have this kind of info ?

        --
        Alex
        [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
        autres jeux de role.



        Comment

        • Alex

          #5
          Re: PHP to a COM object

          "Steve" <no.one@example .comwrote in message
          news:LsE_i.19$w L7.17@newsfe07. lga...
          as in, you're a beginner to VB or, a beginner to php?
          to COM :) and I havent touched VB since..... Win 3.11. :) I've been coding
          in PHP for almost 10 years, but never had to use COM.
          i'd create a component if you need to break this and other com objects
          apart like this.
          >
          if you're using vb classic (the crusty old version), there are several
          free and well written libraries that can expose any com object's
          interfaces...in cluding types, params, etc.
          >
          if you're using vb.net, use it's reflection capabilities to do the same.
          give your vb app the path to the dll, let it create it, and then go about
          discovering its make-up.
          >
          either way, compile it to a com object to make it accessible to php. btw,
          if using vb.net, you don't have to create in php the object being exposed.
          your reflection-enabled com object can not only break-down the interfaces
          for you, but you can also put 'invoke' methods on your object which defers
          to the interface of the child object being exposed to php. make sense?
          The object is already compiled. It's from a software vendor. I meant to say
          that I have doc with the object, but all the examples of object usage are in
          VB, which I have long forgotten. They use lists, for example all around the
          place, and I don't remember how to translate this to PHP :)

          --
          Alex
          [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
          autres jeux de role.



          Comment

          • Alex

            #6
            Re: PHP to a COM object


            "Csaba Gabor" <danswer@gmail. comwrote in message
            news:1195050450 .117726.188090@ 57g2000hsv.goog legroups.com...
            I know how to RTFM :)

            Things are getting a bit "better" now : I replaced new COM() by com_load()
            and voila, I have com_print_typei nfo working. Now I have to understand how
            to access those lists they speak about in the doc.

            That got rid of the errors "is not a COM object handler" I had in the PHP
            log which I just had enabled.

            --
            Alex
            [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
            autres jeux de role.



            Comment

            • Steve

              #7
              Re: PHP to a COM object


              "Alex" <d_keyoke@hotma il.comwrote in message
              news:473b2213$0 $20126$426a74cc @news.free.fr.. .
              "Steve" <no.one@example .comwrote in message
              news:LsE_i.19$w L7.17@newsfe07. lga...
              >as in, you're a beginner to VB or, a beginner to php?
              >
              to COM :) and I havent touched VB since..... Win 3.11. :) I've been coding
              in PHP for almost 10 years, but never had to use COM.
              >
              >i'd create a component if you need to break this and other com objects
              >apart like this.
              >>
              >if you're using vb classic (the crusty old version), there are several
              >free and well written libraries that can expose any com object's
              >interfaces...i ncluding types, params, etc.
              >>
              >if you're using vb.net, use it's reflection capabilities to do the same.
              >give your vb app the path to the dll, let it create it, and then go about
              >discovering its make-up.
              >>
              >either way, compile it to a com object to make it accessible to php. btw,
              >if using vb.net, you don't have to create in php the object being
              >exposed. your reflection-enabled com object can not only break-down the
              >interfaces for you, but you can also put 'invoke' methods on your object
              >which defers to the interface of the child object being exposed to php.
              >make sense?
              >
              The object is already compiled.
              that wasn't the point i was making above...at all. however, no need to get
              into that since that suggestion isn't your intended purpose.
              It's from a software vendor. I meant to say that I have doc with the
              object, but all the examples of object usage are in VB, which I have long
              forgotten. They use lists, for example all around the place, and I don't
              remember how to translate this to PHP :)
              so, you know the object's interfaces...ju st not how to code it in php? same
              way as any other object...

              $o->interface;
              $o->interface(para m);

              etc.

              am i missing something?


              Comment

              • Alex

                #8
                Re: PHP to a COM object

                "Steve" <no.one@example .comwrote in message
                news:odG_i.89$q J1.84@newsfe06. lga...
                >It's from a software vendor. I meant to say that I have doc with the
                >object, but all the examples of object usage are in VB, which I have long
                >forgotten. They use lists, for example all around the place, and I don't
                >remember how to translate this to PHP :)
                >
                so, you know the object's interfaces...ju st not how to code it in php?
                same way as any other object...
                >
                $o->interface;
                $o->interface(para m);
                etc.
                >
                am i missing something?
                I'm pretty sure you're missing a lot less than I do :)

                But it's getting better. I replaced "new COM()" by com_load() and now I can
                use com_print_typei nfo which returns all the innards of the object. I don't
                really know why com_load works better, but it is the case.

                I also got to access one of the lists in the object. $....->item($i) . I'm
                not sure whether it's a special syntax instead of item[$i] or those item()s
                are really functions.

                So things are getting better :)


                However, my next blocking point is something called a factory. It is a
                property of my COM object that is itself an ever-existing instance of a
                class containing other objects. I think it is instanciated automatically by
                the COM server when I create the object.

                Everytime I put its name in my code ( $a =$obj->Factory; nothing more ),
                Apache bombs with no explanation.

                I have put the memory limit for PHP to 128M just to see but it doesnt change
                anything.


                --
                Alex
                [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
                autres jeux de role.



                Comment

                • Steve

                  #9
                  Re: PHP to a COM object


                  "Alex" <d_keyoke@hotma il.comwrote in message
                  news:473b3bee$0 $30024$426a74cc @news.free.fr.. .
                  "Steve" <no.one@example .comwrote in message
                  news:odG_i.89$q J1.84@newsfe06. lga...
                  >>It's from a software vendor. I meant to say that I have doc with the
                  >>object, but all the examples of object usage are in VB, which I have
                  >>long forgotten. They use lists, for example all around the place, and I
                  >>don't remember how to translate this to PHP :)
                  >>
                  >so, you know the object's interfaces...ju st not how to code it in php?
                  >same way as any other object...
                  >>
                  >$o->interface;
                  >$o->interface(para m);
                  >
                  >etc.
                  >>
                  >am i missing something?
                  >
                  I'm pretty sure you're missing a lot less than I do :)
                  >
                  But it's getting better. I replaced "new COM()" by com_load() and now I
                  can use com_print_typei nfo which returns all the innards of the object. I
                  don't really know why com_load works better, but it is the case.
                  >
                  I also got to access one of the lists in the object. $....->item($i) . I'm
                  not sure whether it's a special syntax instead of item[$i] or those
                  item()s are really functions.
                  >
                  So things are getting better :)
                  >
                  >
                  However, my next blocking point is something called a factory. It is a
                  property of my COM object that is itself an ever-existing instance of a
                  class containing other objects. I think it is instanciated automatically
                  by the COM server when I create the object.
                  >
                  Everytime I put its name in my code ( $a =$obj->Factory; nothing more ),
                  try:

                  $a = $obj->Factory();


                  Comment

                  • Alex

                    #10
                    Re: PHP to a COM object


                    "Alex" <d_keyoke@hotma il.comwrote in message
                    news:473b3bee$0 $30024$426a74cc @news.free.fr.. .
                    "Steve" <no.one@example .comwrote in message
                    news:odG_i.89$q J1.84@newsfe06. lga...
                    >>It's from a software vendor. I meant to say that I have doc with the
                    >>object, but all the examples of object usage are in VB, which I have
                    >>long forgotten. They use lists, for example all around the place, and I
                    >>don't remember how to translate this to PHP :)
                    >>
                    >so, you know the object's interfaces...ju st not how to code it in php?
                    >same way as any other object...
                    >>
                    >$o->interface;
                    >$o->interface(para m);
                    >
                    >etc.
                    >>
                    >am i missing something?
                    >
                    I'm pretty sure you're missing a lot less than I do :)
                    >
                    But it's getting better. I replaced "new COM()" by com_load() and now I
                    can use com_print_typei nfo which returns all the innards of the object. I
                    don't really know why com_load works better, but it is the case.
                    >
                    I also got to access one of the lists in the object. $....->item($i) . I'm
                    not sure whether it's a special syntax instead of item[$i] or those
                    item()s are really functions.
                    >
                    So things are getting better :)
                    >
                    >
                    However, my next blocking point is something called a factory. It is a
                    property of my COM object that is itself an ever-existing instance of a
                    class containing other objects. I think it is instanciated automatically
                    by the COM server when I create the object.
                    >
                    Everytime I put its name in my code ( $a =$obj->Factory; nothing more ),
                    Apache bombs with no explanation.
                    >
                    I have put the memory limit for PHP to 128M just to see but it doesnt
                    change anything.
                    Oh there's something I just realized.

                    This "factory" object is an instance of a class called Factory. But the doc
                    also makes mention of something called an interface (IFactory) who has the
                    same methods/Properties of the class. When I do a com_print_typei nfo on the
                    Factory, I get almost nothing :
                    class Factory { /* GUID={F4E856D4-FCD7-11D4-9D8A-0001029DEAF5} */
                    }When I do it on the interface, I get all my object's properties.

                    There HAS to be a difference :)

                    --
                    Alex
                    [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
                    autres jeux de role.



                    Comment

                    • Alex

                      #11
                      Re: PHP to a COM object

                      "Steve" <no.one@example .comwrote in message
                      news:86H_i.35$w L7.20@newsfe07. lga...
                      try:
                      >
                      $a = $obj->Factory();
                      Just did it.... Apache inflates to 51M of RAM usage and bombs. grmf :)

                      --
                      Alex
                      [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
                      autres jeux de role.



                      Comment

                      • Steve

                        #12
                        Re: PHP to a COM object


                        "Alex" <d_keyoke@hotma il.comwrote in message
                        news:473b3ff8$0 $20124$426a74cc @news.free.fr.. .
                        "Steve" <no.one@example .comwrote in message
                        news:86H_i.35$w L7.20@newsfe07. lga...
                        >
                        >try:
                        >>
                        >$a = $obj->Factory();
                        >
                        Just did it.... Apache inflates to 51M of RAM usage and bombs. grmf :)
                        did you say you set your memory limit to -1 (unlimited) in php?

                        does Factory take a param to just return a single item?

                        the good new is that it seem to be just a memory issue at this point.


                        Comment

                        • Steve

                          #13
                          Re: PHP to a COM object


                          "Alex" <d_keyoke@hotma il.comwrote in message
                          news:473b3f32$0 $29354$426a74cc @news.free.fr.. .
                          >
                          "Alex" <d_keyoke@hotma il.comwrote in message
                          news:473b3bee$0 $30024$426a74cc @news.free.fr.. .
                          >"Steve" <no.one@example .comwrote in message
                          >news:odG_i.89$ qJ1.84@newsfe06 .lga...
                          >>>It's from a software vendor. I meant to say that I have doc with the
                          >>>object, but all the examples of object usage are in VB, which I have
                          >>>long forgotten. They use lists, for example all around the place, and I
                          >>>don't remember how to translate this to PHP :)
                          >>>
                          >>so, you know the object's interfaces...ju st not how to code it in php?
                          >>same way as any other object...
                          >>>
                          >>$o->interface;
                          >>$o->interface(para m);
                          >>
                          >>etc.
                          >>>
                          >>am i missing something?
                          >>
                          >I'm pretty sure you're missing a lot less than I do :)
                          >>
                          >But it's getting better. I replaced "new COM()" by com_load() and now I
                          >can use com_print_typei nfo which returns all the innards of the object. I
                          >don't really know why com_load works better, but it is the case.
                          >>
                          >I also got to access one of the lists in the object. $....->item($i) .
                          >I'm not sure whether it's a special syntax instead of item[$i] or those
                          >item()s are really functions.
                          >>
                          >So things are getting better :)
                          >>
                          >>
                          >However, my next blocking point is something called a factory. It is a
                          >property of my COM object that is itself an ever-existing instance of a
                          >class containing other objects. I think it is instanciated automatically
                          >by the COM server when I create the object.
                          >>
                          >Everytime I put its name in my code ( $a =$obj->Factory; nothing more ),
                          >Apache bombs with no explanation.
                          >>
                          >I have put the memory limit for PHP to 128M just to see but it doesnt
                          >change anything.
                          >
                          Oh there's something I just realized.
                          >
                          This "factory" object is an instance of a class called Factory. But the
                          doc also makes mention of something called an interface (IFactory) who has
                          the same methods/Properties of the class. When I do a com_print_typei nfo
                          on the Factory, I get almost nothing :
                          class Factory { /* GUID={F4E856D4-FCD7-11D4-9D8A-0001029DEAF5} */
                          }When I do it on the interface, I get all my object's properties.
                          >
                          There HAS to be a difference :)
                          a difference, yes. something that will make your code quit bombing and still
                          get the Factory functionality.. .probably not. all an interface (IFactory in
                          this case) is, is a contract...a definition of what *all usable* objects
                          that *implement* that interface will provide a caller, i.e. your php code.
                          make sense? IFactory will provide you no other functionality than that.
                          here's an example in vb.

                          public interface iFactory
                          public property foo as integer
                          end interface

                          public class sawMill
                          implements iFactory
                          public property get foo() implements iFactory.foo
                          get
                          return 666
                          end get
                          set (byval value as integer)
                          # do nothing...howev er, set is *required*
                          # because iFactory is read/write
                          end property
                          public function saw()
                          debug.print "sawing..."
                          end function
                          end class

                          public class brewery
                          implements iFactory
                          private myFoo as integer
                          public property get foo() implements iFactory.foo
                          get
                          return myFoo
                          end get
                          set (byval value as integer)
                          myFoo = value
                          end property
                          public function brew()
                          debug.print "brewing " & myFoo
                          end function
                          end class

                          in the above, both completely unrelated classes (sawMill and brewery) have
                          iFactory.foo as part of their definition. how they implement them is
                          different, but each must have a read and write foo.

                          if i simply say:

                          private myFactory as iFactory

                          and then try:

                          myFactory.foo()

                          it will do nothing. myFactory is an interface that has no working parts.
                          however, if i do:

                          private myFactory as iFactory = new brewery
                          myFactory.foo = 15

                          i'll get somewhere. notice that the above works whether or not i set
                          myFactory to new brewery OR sawMill. both have a foo interface. however, if
                          i continue the above code with:

                          myFactory.saw()

                          it'll blow up. both saw and brew are specific interfaces defined by each
                          class respectively... not by iFactory. let's say that myFactory is set
                          somewhere unbeknownst to me, how would i take specific action?

                          public function factoryToString (byval factory as iFactory, byval fooValue as
                          integer)
                          factory.foo = fooValue
                          if typeof factory is sawMill then
                          factory.saw()
                          end if
                          if typeof factory is brewery then
                          factory.brew()
                          end if
                          end function

                          anyway...i think i got off track, but does that help you know that you're
                          going to have to get at an actual Factory object in the list...which doesn't
                          solve your memory problem?


                          Comment

                          • Alex

                            #14
                            Re: PHP to a COM object

                            "Steve" <no.one@example .comwrote in message
                            news:mKH_i.34$d m.33@newsfe02.l ga...
                            a difference, yes. something that will make your code quit bombing and
                            still get the Factory functionality.. .probably not. all an interface
                            (IFactory in this case) is, is a contract...a definition of what *all
                            usable* objects that *implement* that interface will provide a caller,
                            i.e. your php code. make sense? IFactory will provide you no other
                            functionality than that. here's an example in vb.
                            OK it's like a class from which another inherits, then ?

                            (snip the example)
                            anyway...i think i got off track, but does that help you know that you're
                            going to have to get at an actual Factory object in the list...which
                            doesn't solve your memory problem?
                            Yes, that's very helpful. But it raises a question in PHP. Can I assume that
                            COM tells PHP what type the objects in a class (or Interface) are ? I don't
                            have to explicitely instanciate or cast the objects that are childs of a COM
                            object ?

                            Now, I tried different values for memory_limit in php.ini and it doesnt
                            change anything. I had a closer look at the memory usage, and Apache also
                            takes almost 50M on a working page. So I'm not really sure it's a memory
                            problem.

                            Actually, the COM syntax is not really complicated. So I'm beginning to
                            think of a bug (in the object or PHP).

                            I'm considering trying a newer version of PHP. But I fear the impacts.

                            Thank you very much again, things are getting clearer :)
                            --
                            Alex
                            [JDR] Visitez Extremia, un monde gratuit et en francais pour D&D et
                            autres jeux de role.



                            Comment

                            • Csaba Gabor

                              #15
                              Re: PHP to a COM object

                              Steve, thanks for your awesome exposition on VB interfaces, replete
                              with example. This type of post is all too rare on the web.

                              Csaba

                              On Nov 14, 8:10 pm, "Steve" <no....@example .comwrote:
                              "Alex" <d_key...@hotma il.comwrote in message
                              ....
                              a difference, yes. something that will make your code quit bombing and still
                              get the Factory functionality.. .probably not. all an interface (IFactory in
                              this case) is, is a contract...a definition of what *all usable* objects
                              that *implement* that interface will provide a caller, i.e. your php code.
                              make sense? IFactory will provide you no other functionality than that.
                              here's an example in vb.
                              >
                              public interface iFactory
                              public property foo as integer
                              end interface
                              >
                              public class sawMill
                              implements iFactory
                              public property get foo() implements iFactory.foo
                              get
                              return 666
                              end get
                              set (byval value as integer)
                              # do nothing...howev er, set is *required*
                              # because iFactory is read/write
                              end property
                              public function saw()
                              debug.print "sawing..."
                              end function
                              end class
                              >
                              public class brewery
                              implements iFactory
                              private myFoo as integer
                              public property get foo() implements iFactory.foo
                              get
                              return myFoo
                              end get
                              set (byval value as integer)
                              myFoo = value
                              end property
                              public function brew()
                              debug.print "brewing " & myFoo
                              end function
                              end class
                              >
                              in the above, both completely unrelated classes (sawMill and brewery) have
                              iFactory.foo as part of their definition. how they implement them is
                              different, but each must have a read and write foo.
                              >
                              if i simply say:
                              >
                              private myFactory as iFactory
                              >
                              and then try:
                              >
                              myFactory.foo()
                              >
                              it will do nothing. myFactory is an interface that has no working parts.
                              however, if i do:
                              >
                              private myFactory as iFactory = new brewery
                              myFactory.foo = 15
                              >
                              i'll get somewhere. notice that the above works whether or not i set
                              myFactory to new brewery OR sawMill. both have a foo interface. however, if
                              i continue the above code with:
                              >
                              myFactory.saw()
                              >
                              it'll blow up. both saw and brew are specific interfaces defined by each
                              class respectively... not by iFactory. let's say that myFactory is set
                              somewhere unbeknownst to me, how would i take specific action?
                              >
                              public function factoryToString (byval factory as iFactory, byval fooValue as
                              integer)
                              factory.foo = fooValue
                              if typeof factory is sawMill then
                              factory.saw()
                              end if
                              if typeof factory is brewery then
                              factory.brew()
                              end if
                              end function
                              >
                              anyway...i think i got off track, but does that help you know that you're
                              going to have to get at an actual Factory object in the list...which doesn't
                              solve your memory problem?

                              Comment

                              Working...