| Author |
Automagic Creation of Accessor Methods ~ any advice?
|
|
| jerrygarciuh 2005-02-22, 8:56 pm |
| 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 2005-02-23, 8:56 pm |
| "jerrygarciuh" <designs@no.spam.nolaflash.com> wrote in message
news:yoOSd.4956$SF.1881@lakeread08...
> 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
>
It's called eval().
| |
|
| On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarciuh"
<designs@no.spam.nolaflash.com> wrote:
>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.
Don't we all. I'm about to write my 2nd or 3rd database abstraction
layer.
>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.
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().
>Can anyone point me to a good reference on creating class methods on the fly
>in PHP?
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.
| |
| Matt Mitchell 2005-02-24, 3:56 pm |
| : On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarciuh"
: <designs@no.spam.nolaflash.com> wrote:
:
: >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.
You might be happier doing all this in Perl instead...
| |
| jerrygarciuh 2005-02-24, 3:56 pm |
| Matt,
Isn't that always true?
jg
"Matt Mitchell" < m_a_t_t_remove_the_underscores@metalspon
ge.net> wrote in
message news:H_kTd.138717$68.68612@fe1.news.blueyonder.co.uk...
>: On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarciuh"
> : <designs@no.spam.nolaflash.com> wrote:
> :
> : >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.
>
> You might be happier doing all this in Perl instead...
>
>
| |
| jerrygarciuh 2005-02-24, 3:56 pm |
| 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:lfeq11pe23se484nkrok60gkuqco2bon4r@
4ax.com...
> On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarciuh"
> <designs@no.spam.nolaflash.com> wrote:
>
>
> Don't we all. I'm about to write my 2nd or 3rd database abstraction
> layer.
>
>
> 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().
>
>
> 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.
>
| |
| Andy Hassall 2005-02-24, 8:56 pm |
| On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarciuh"
<designs@no.spam.nolaflash.com> wrote:
>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!
If you're using PHP5 you could use:
http://www.php.net/manual/en/langua...overloading.php
... 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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
|
|
|
|