__construct() shortcommings??

I have a function, which I call setter(). This function formats certain varibles, ready for and SQL feed
for eg

$instance -> table = "members";
will be formatted to $this->table = "FROM ".$this->table;

There are serveral other memer functions that use this function so that the SQL query is in the proper syntax.

The problem I have is that the other member functions also use each other to do the job. This results in multiple call to the setter() function. Consequently the query fed into SQL sometimes looks like this : SELECT * FROM FROM FROM.
As you can see, there are more FROMs than SQL can accomodate.

When I migrated to PHP5, I discovered the __contruct() functions, which I thought I could use to load this setter() function so I dont have to call it in the other member functions.

The problem I have come across is that the __construct() is called BEFORE all the member variables have had the chace to load.
The result is that the setter() doesnt have any data to work on and so becomes useless.

Any suggestions appreciatedThe __construct function is used to define a constructor. A constructor is used to initialise the state of the new object (i.e., provide member variables with initial values and perform other housekeeping tasks).

Now, if you define __construct() such that you are able to pass it the values by which the object can be initialised, then you can call setter() within __construct(). However, if you want to allow the class user to defer such assignment of values where setter() is concerned, then __construct() cannot call setter().

In fact, why use setter() at all? You might as well provide a setter function for each member variable in question.
 
Top