Naming php files

前端 未结 6 606
闹比i
闹比i 2021-02-02 14:08

Is there any convention for naming php files? Not talking about php class files, but files that are mostly HTML with some php inside them. Should it be my-file-example.php

相关标签:
6条回答
  • 2021-02-02 14:31

    PSR-4 recommends using a directory hierarchy to represent the namespace.

    For Object-Oriented programming, the autoloader can simplify code management with relatively little cost overhead at run time. This requires the capability to determine a file path from a class name - hence a linear transform of the latter is a good idea. This might be as simple as $className . ".php"

    0 讨论(0)
  • 2021-02-02 14:32

    I would suggest you to use underscore separators my_file_example.php, CodeIgniter for example use this convention for it's view files.

    With dashes, some IDE/Text Editor don't select all the filname by double clicking on it, while with underscore it select, generally, all the file name.

    0 讨论(0)
  • 2021-02-02 14:36

    There are usually 2 conventions you need to take into consideration:

    1. used framework
    2. PSR-4

    In best scenario these 2 are the same. I usually try to avoid cases when a framework tries to force some custom rules.

    Either way, the MOST important is to stay consistent throughout the project. Once you pick a convention to follow, stick with it until you start working on a different project. There's nothing worse than different naming conventions in a single project, doesn't matter if we're talking about files, classes, methods or whatever. Be consistent.

    0 讨论(0)
  • 2021-02-02 14:39

    There is no specific for the core php files you have to use your own naming convention, but you can name on the bases of you file work.

    Like php file is only display the html then give my_file_view.php if it has database operation then my_file_db.php

    and so on for the function and for other specification you can use it.

    0 讨论(0)
  • 2021-02-02 14:40

    There is no really convention for PHP files.

    You just should keep the same in your project.

    I recommand you to use camelCase.

    0 讨论(0)
  • 2021-02-02 14:55

    You'll come across packages using filenames as

    class.phpmailer.php or
    ImapMailbox.php
    

    (both containing classes with ClassName {})

    (Personally, I use camelCase heavily for fnames, from var-habits i guess. )

    0 讨论(0)
提交回复
热议问题