473,804 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 17 '05 #1
6 2005
"jerrygarci uh" <de*****@no.spa m.nolaflash.com > wrote in message
news:yoOSd.4956 $SF.1881@lakere ad08...
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().
Jul 17 '05 #2
On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
<de*****@no.spa m.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'
relationship s 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.

Jul 17 '05 #3
: On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
: <de*****@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...
Jul 17 '05 #4
Matt,

Isn't that always true?

jg
"Matt Mitchell" <m_************ *************** *@metalsponge.n et> wrote in
message news:H_******** ***********@fe1 .news.blueyonde r.co.uk...
: On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
: <de*****@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...

Jul 17 '05 #5
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" <no*@here.com > wrote in message
news:lf******** *************** *********@4ax.c om...
On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
<de*****@no.spa m.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'
relationshi ps 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.

Jul 17 '05 #6
On Tue, 22 Feb 2005 16:30:54 -0600, "jerrygarci uh"
<de*****@no.spa m.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'
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!


If you're using PHP5 you could use:

http://www.php.net/manual/en/languag...verloading.php

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

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5657
by: Richard | last post by:
Hi all, I am looking for some help on understanding the overhead associated with object creation in Java. I am writing an application where I have written a class to encapsulate some text data. The class is contains these private variables:
22
6794
by: mirandacascade | last post by:
When I look at how classes are set up in other languages (e.g. C++), I often observe the following patterns: 1) for each data member, the class will have an accessor member function (a Get<whatever> function) 2) for each data member, the class will have a mutator member function (a Set<whatver> function) 3) data members are never referenced directly; they are always referenced with the accessor and mutator functions My questions are:
2
2069
by: Todd A. Anderson | last post by:
I've inherited two "C++" code bases that I have to tie together and both of them make frequest use of public member variables in spite of all the information saying this limits flexibility. Well, their lack of foresight has bit me of course! I'd like to start off by converting all their public member variable accesses to the use of accessor methods. Then, I can reimplement selected accessor methods to provide the necessary glue between...
22
12042
by: Generic Usenet Account | last post by:
A lot has been said in this newsgroup regarding the "evil" set/get accessor methods. Arthur Riel, (of Vanguard Training), in his class, "Heuristis for O-O Analysis & Design", says that there is almost never an excuse for accessor methods. Personally, I do not go that far. I do feel that they serve a useful purpose (albeit in a limited manner). Personally I prefer dropping the "set" and "get" prefixes from the method names altogether. ...
3
4552
by: LuCk | last post by:
Can someone explain what these really are for example: ---------------------------------------------------------- void SetFrameRate(int iFrameRate) { m_iFrameDelay = 1000 / iFrameRate; }; ---------------------------------------------------------- I know what functions are and i know what void is and stuff but i dont get the whole `Accessor Methods` term i guess.
6
2974
by: Jason Shohet | last post by:
I have a class with protected variables and some accessor methods, , get, set ... Maybe I have a brain blockage today but I'm thinking, why not just make those variables public. After all, someone can do just as great harm by misusing a set { } accessor method as just doing myObj.lastname = "Big Bird"; which he could do in a second class, if the variable is public on the first class. IOTW, what does keeping with the protected /...
7
2365
by: Tenacious | last post by:
I have been programming using C# for over a year now and I still wonder what is the importance of using accessor methods when the property is read-write. It seems easier to just make it a public property of the class, but I have read in more than one book that this is a bad practice. The books did not mention the reason why this is a bad practice. Can anybody give me some insight on this?
8
1787
by: AAJ | last post by:
Hi all I would like to have a class that can set/return values of different datatype via a single accessor, i.e. overload the accessor i.e. something like DateTime m_DateValue; string m_StringValue;
8
8243
by: Tim Sprout | last post by:
Why is it considerd best practice to use Properties rather than Get and Set accessor methods? -Tim Sprout
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.