Q:

Proper PHP coding style

I'm working on a new project that is going to make heavy use of different AJAX calls to PHP.  Is it proper to create one file that contains all the different functions and use a case statement to pick the proper one, or should I create a php folder and put each function in its own file?
I'm trying to get my skills back on track with modern web design standards and practices, and in the past, one file to rule them all was the way to go for simplicity sake; however, so much has changed that I wanted to ask before I got 10,000 lines into this project.
Thank you for any advice you can provide.

A:

This question will illicit a lot of personal opinion.
Case and point, my opinion:
Code re-usability is key of any programming language. Store like functions together in an include file, include the type (or however else you organized your functions) in the main module in which you need those functions in. You shouldn't put one function per file, but at the same time one huge file with 400 functions in it would be a nightmare.

A:

Instead of thinking about the implementation of the problem why not think about the interface?
This is what I mean, you could separate the real work to done in classes somewhere, and let the ajax make calls to another separate classes/function. Then the functions called through ajax can query the different classes/objects to accomplish the work and send respond back to ajax. It may sound like the MVC pattern. The advantage of this is clearly code reusability , improved decoupling and easier code maintenance.
Example:
class Cook{

    function friedEgg(){/**/}
    function currySoup(){/**/}
    function sandwich(){/**/}
}

And function called through ajax could be 
function ajaxBreakfast(){
    $cook = new Cook;
    $result = $cook->friedEgg();
    $result .= $cook->sandwich();
    echo $result;
}

function ajaxLunch(){
    $cook = new Cook;
    $result = $cook->currySoup();
    echo $result;
}

Hope you get my point!

