A while back we had a meeting in my ex-workplace regarding how we design our webpages (the backend). The meeting ended up with (among others) the decision to convert our PHP scripts into object oriented PHP.
Before that, all our scripts are scattered in its own file, and whenever we need to make use of a function (eg: Search for something), we'll include_once() or require_once() the file and use it to complete our tasks.
Now, they are starting to convert those scripts and make them into classes. So, to search for something, the current page will have to create an object of search, then call the method defined in the class.
Personally, i don't really see the benefit of doing class-based (object oriented) programming for a script (or page) that will only be interpreted as it is being read. That is, if i go to http://localhost/myscript.php, i think it's more efficient and easier to just do require_once() on external scripts and run the functions defined in that external script, instead of doing require_once() to load the class, create the object, then call the method to do the tasks.
Am i wrong in this view? Is there an advantage of doing class-based web programming in PHP? Or any interpreted language at all? Other than the inheritance of methods, i don't see anything big...
Please shed a light on this.
Thank you.
Summary:
Example: A search script needs to include external scripts to do database connection, run the search, and display the results in HTML format.
Me: When executing PHP script, just do require_once() to load external scripts, then run the functions to accomplish the task. This includes the functions to print the HTML <head>, <body>, and the page contents.
Them: When executing PHP script, it is better to require_once() classes, create an instance of that class, then call the methods defined in that class to accomplish the task. This includes the methods to print the HTML <head>, <body>, and the page contents.
Question: Any dis/advantages of class-based script execution compared to regular file-include execution? Speed? Simplicity? Use of extra resources to create objects? Others?
Before that, all our scripts are scattered in its own file, and whenever we need to make use of a function (eg: Search for something), we'll include_once() or require_once() the file and use it to complete our tasks.
Now, they are starting to convert those scripts and make them into classes. So, to search for something, the current page will have to create an object of search, then call the method defined in the class.
Personally, i don't really see the benefit of doing class-based (object oriented) programming for a script (or page) that will only be interpreted as it is being read. That is, if i go to http://localhost/myscript.php, i think it's more efficient and easier to just do require_once() on external scripts and run the functions defined in that external script, instead of doing require_once() to load the class, create the object, then call the method to do the tasks.
Am i wrong in this view? Is there an advantage of doing class-based web programming in PHP? Or any interpreted language at all? Other than the inheritance of methods, i don't see anything big...
Please shed a light on this.
Thank you.
Summary:
Example: A search script needs to include external scripts to do database connection, run the search, and display the results in HTML format.
Me: When executing PHP script, just do require_once() to load external scripts, then run the functions to accomplish the task. This includes the functions to print the HTML <head>, <body>, and the page contents.
Them: When executing PHP script, it is better to require_once() classes, create an instance of that class, then call the methods defined in that class to accomplish the task. This includes the methods to print the HTML <head>, <body>, and the page contents.
Question: Any dis/advantages of class-based script execution compared to regular file-include execution? Speed? Simplicity? Use of extra resources to create objects? Others?