Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper PHP coding style

Tags:

php

standards

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.

like image 850
FireCrakcer37 Avatar asked Feb 20 '23 08:02

FireCrakcer37


1 Answers

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.

like image 65
PenguinCoder Avatar answered Feb 22 '23 23:02

PenguinCoder