How many lines of PHP code is too many for one file?

前端 未结 8 2364
日久生厌
日久生厌 2021-02-20 15:55

I\'m creating a PHP file that does 2 mysql database calls and the rest of the script is if statements for things like file_exists and other simple variables. I have about 2000

8条回答
  •  清酒与你
    2021-02-20 16:16

    I would say there should not be any performance issue related to the number of lines in your php files, it can be as big as you need.

    Now, for the patterns and best practices, I would say that you have to judge by yourself, I saw many well organized files of several thousand lines and a lot of actually small and difficult to read files. My advise would be:

    • Judge the readability of the source code, always organize it well.
    • It's important to have a logical separation to some extent, if your file does both: heavy database access, writing, modification, html rendering, ajax and so on.. You may want to separate things or use object oriented approach.
    • Always search the balance between the logical separation and code. It should not be messy nor extra-neat with a lot of 10-line files

提交回复
热议问题