Separate PHP files

Which method is better:

  1. A php file that likes, votes, deletes, adds, etc a post on a page.
  2. Several php files that each one does one thing. a file for voting a post, another for liking a post, etc on a page.

Depends.

(Question far too vague to give concrete opinion.)

1 Like

A single entry point that acts as a front-end controller to delegate requests to the proper action. The entry point file would be very light in code and simple only pulling in other files/classes that initiate the entire application workflow/execution processes. When you’re building an application you shouldn’t think in “files” but rather controllers and actions that are executed using some type of routing system using a single entry point. Start looking into MVC frameworks like Symfony and Laravel – that is how aprofessional PHP application should be structured. Anything less is really just anything less that is going to suffer from a host of maintenance issues down the line.

3 Likes