Automagic Creation of Accessor Methods ~ any advice?

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

    #1

    Automagic Creation of Accessor Methods ~ any advice?

    Hello,

    I have been working for some time now on a PHP OOP database abstraction
    layer. Yes I know there are others out there which are maturing but I like
    reinventing this wheel.

    The task I have at hand is that I want to specify 'has a' and 'has many'
    relationships in an array for each class and use these to automagically
    create the accessor methods and perhaps mutator methods as well.

    Can anyone point me to a good reference on creating class methods on the fly
    in PHP?

    I have spent the afternoon studying how Perl's lovely Class::DBI handles
    this but I can't get my head around how I would create these methods based
    on my array values in PHP.

    Any pointers and links greatly appreciated!

    jg


  • Chung Leong

    #2
    Re: Automagic Creation of Accessor Methods ~ any advice?

    "jerrygarci uh" <designs@no.spa m.nolaflash.com > wrote in message
    news:yoOSd.4956 $SF.1881@lakere ad08...[color=blue]
    > Hello,
    >
    > I have been working for some time now on a PHP OOP database abstraction
    > layer. Yes I know there are others out there which are maturing but I[/color]
    like[color=blue]
    > reinventing this wheel.
    >
    > The task I have at hand is that I want to specify 'has a' and 'has many'
    > relationships in an array for each class and use these to automagically
    > create the accessor methods and perhaps mutator methods as well.
    >
    > Can anyone point me to a good reference on creating class methods on the[/color]
    fly[color=blue]
    > in PHP?
    >
    > I have spent the afternoon studying how Perl's lovely Class::DBI handles
    > this but I can't get my head around how I would create these methods based
    > on my array values in PHP.
    >
    > Any pointers and links greatly appreciated!
    >
    > jg
    >[/color]

    It's called eval().


    Comment

    • Wayne

      #3
      Re: Automagic Creation of Accessor Methods ~ any advice?

      On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
      <designs@no.spa m.nolaflash.com > wrote:
      [color=blue]
      >I have been working for some time now on a PHP OOP database abstraction
      >layer. Yes I know there are others out there which are maturing but I like
      >reinventing this wheel.[/color]

      Don't we all. I'm about to write my 2nd or 3rd database abstraction
      layer.
      [color=blue]
      >The task I have at hand is that I want to specify 'has a' and 'has many'
      >relationship s in an array for each class and use these to automagically
      >create the accessor methods and perhaps mutator methods as well.[/color]

      Well if you are using PHP5 than you have lots of options available.
      Thankfully my project is in PHP5 and get to use those options. If
      you're using PHP4 than your only option is to use eval().
      [color=blue]
      >Can anyone point me to a good reference on creating class methods on the fly
      >in PHP?[/color]

      The only problem with using eval() is that you cannot add methods to a
      class this way. You can, however, build entire classes with eval()
      which might be the way to go.

      Comment

      • Matt Mitchell

        #4
        Re: Automagic Creation of Accessor Methods ~ any advice?

        : On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
        : <designs@no.spa m.nolaflash.com > wrote:
        :
        : >The task I have at hand is that I want to specify 'has a' and 'has many'
        : >relationship s in an array for each class and use these to automagically
        : >create the accessor methods and perhaps mutator methods as well.

        You might be happier doing all this in Perl instead...


        Comment

        • jerrygarciuh

          #5
          Re: Automagic Creation of Accessor Methods ~ any advice?

          Matt,

          Isn't that always true?

          jg


          "Matt Mitchell" <m_a_t_t_remove _the_underscore s@metalsponge.n et> wrote in
          message news:H_kTd.1387 17$68.68612@fe1 .news.blueyonde r.co.uk...[color=blue]
          >: On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
          > : <designs@no.spa m.nolaflash.com > wrote:
          > :
          > : >The task I have at hand is that I want to specify 'has a' and 'has
          > many'
          > : >relationship s in an array for each class and use these to automagically
          > : >create the accessor methods and perhaps mutator methods as well.
          >
          > You might be happier doing all this in Perl instead...
          >
          >[/color]


          Comment

          • jerrygarciuh

            #6
            Re: Automagic Creation of Accessor Methods ~ any advice?

            Ladies and gentlemen we have a winner!! This is totally what I should do,
            extend the child class to include the new methods!!

            Thank you!

            jg


            "Wayne" <not@here.com > wrote in message
            news:lfeq11pe23 se484nkrok60gku qco2bon4r@4ax.c om...[color=blue]
            > On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
            > <designs@no.spa m.nolaflash.com > wrote:
            >[color=green]
            >>I have been working for some time now on a PHP OOP database abstraction
            >>layer. Yes I know there are others out there which are maturing but I
            >>like
            >>reinventing this wheel.[/color]
            >
            > Don't we all. I'm about to write my 2nd or 3rd database abstraction
            > layer.
            >[color=green]
            >>The task I have at hand is that I want to specify 'has a' and 'has many'
            >>relationshi ps in an array for each class and use these to automagically
            >>create the accessor methods and perhaps mutator methods as well.[/color]
            >
            > Well if you are using PHP5 than you have lots of options available.
            > Thankfully my project is in PHP5 and get to use those options. If
            > you're using PHP4 than your only option is to use eval().
            >[color=green]
            >>Can anyone point me to a good reference on creating class methods on the
            >>fly
            >>in PHP?[/color]
            >
            > The only problem with using eval() is that you cannot add methods to a
            > class this way. You can, however, build entire classes with eval()
            > which might be the way to go.
            >[/color]


            Comment

            • Andy Hassall

              #7
              Re: Automagic Creation of Accessor Methods ~ any advice?

              On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
              <designs@no.spa m.nolaflash.com > wrote:
              [color=blue]
              >I have been working for some time now on a PHP OOP database abstraction
              >layer. Yes I know there are others out there which are maturing but I like
              >reinventing this wheel.
              >
              >The task I have at hand is that I want to specify 'has a' and 'has many'
              >relationship s in an array for each class and use these to automagically
              >create the accessor methods and perhaps mutator methods as well.
              >
              >Can anyone point me to a good reference on creating class methods on the fly
              >in PHP?
              >
              >I have spent the afternoon studying how Perl's lovely Class::DBI handles
              >this but I can't get my head around how I would create these methods based
              >on my array values in PHP.
              >
              >Any pointers and links greatly appreciated![/color]

              If you're using PHP5 you could use:



              ... which can act quite similarly to Perl's AUTOLOAD method to pretend to be
              dynamically created methods.

              --
              Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
              <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

              Comment

              Working...