Q:

Reducing number of php files used in project

I am developing an application in which I have a Class containing various methods. The problem is that i need to call most of the methods on form submission. For that reason, I have to create a new file on each form submission. On every file, I have to create an instance of the same class and then call the appropriate method.
Is there any better way to call methods in such situation so that I don't have to create multiple files having similar functionality in php? I surely don't want to use any framework.

A:

Maybe this is a good point to start applying some design patterns and good old OOP princiles.
AFAIK having many files isn't bad as long as the application is structured correctly.
If you follow the SOLID principles of OOP you will end with a loosely coupled and well structured application.
Actually following the first principle (Single responsibility principle) will result in more classes (and files eventually), but ur code will be more cohesive.

A:

You dont need to create a separate PHP file for each form submission.
<form method="post" action="myapp.php">
 <input type="hidden" name="action" value="useraccount">
 ...
</form>

On the PHP side of things, just check the posted 'action' variable, and respond accordingly.
Actually, what you want to do is to have a master 'view' controller that handles the interface, and load templates of the pages you need through that.  This way you dont have a single php page per web 'page' that the user sees - just the one.  Then you're not creating massive amounts of PHP files, and not duplicating all the include()'s on every page.  If you then have a need to make it look like separate pages for some reason, you use mod_rewrite.

