I am changing my class structure to store common database methods in a class. Then spread it to a child's classroom, it should be cut on the code, but when I need it, I also get permission to overwrite the basic methods.
I did the following, for this example I have simplified the basics compared to the original code, there are more classes.
class parent_object {private $ table_name; Public function all_records () {$ sql = "SELECT * FROM". $ This- & gt; Table_name; Return $ the-> gt; Execute_sql ($ sql); }} Class increases child_object parent_object {protected static $ table_name = "tbl_name"; Public function __ composition () {origin: __ build (self: $ table_name); }}
I want to call all_records () to protect myself to create new objects all the time.
I am stuck to instant my child and then call the basic method
$ child = new child_object (); $ All = $ child- & gt; All_records ();
I really want to be able to call the original method:
$ all = child_object :: all_records ();
I understand that I can not do it with my code, but in some way it would like that the child first inserts and then uses the original method.
I can write All_records () method to instantiate myself in child_object and parents call all_records (), but in this way the code and the same method of cutting my child's class Eliminating the purpose of expansion.
I am sure its very simple or some high level upper function can do this.
Thank you for your help. The answer is relatively simple, you can change all your properties in static properties, and then Can use
. auto ::
instead of static ::
Although solving this problem is considered a bad practice in this way. Best wishes
No comments:
Post a Comment