Extension 'Inc' and MVC in PHP

3

I know that it is not mandatory to use the inc and class codenames in the name of the files, but for the sake of organization it is even recommended.

The doubt is due to the fact that the class codename is easy to understand that it is a classe file, but the inc codename that is include is confusing, this is because in MVC is it ideial in the control directory or should it only be used in files such as autoload?

As I see it, files in control should also use this codename since they make includes , making the connection between view and model .

    
asked by anonymous 09.03.2017 / 02:28

2 answers

1

The file naming is indifferent to MVC or any design patterns.

Including ".inc" and ".class" was an old practice that even many old PHP programmers disagreed with.

Basically, these letters only helped to identify what kind of file it was. If it had ".inc" in the nomenclature, it meant that it was an include file, ie it should not run directly. Idem for ".class" types.

There are also ".func" and ".cons" types, for functions and constants, respectively, and there probably must be others, but these are the best known.

Normally these files should be kept in a private access folder, not accessible by the user. But not everyone could follow this recommendation because N reasons. Lack of knowledge or resources (the host would not allow it).

In general, you'll find nomenclatures like

file.inc.php
file.class.php
file.func.php
file.cons.php

Some omit%% of the end, but that may be a bad idea because you can expose the codes in public if the environment is not well configured.

Old and heavily used systems, such as PHPMyAdmin, still use this practice.

It is worth noting that this is not also bad practice. It is merely a matter of opinion / choice of who creates the project. The important thing is the project to be well written, well documented and organized. The nomenclature matters little as long as you know what you are doing.

    
09.03.2017 / 07:45
3

No inc is not required and is not a de facto standard, in fact there are better standards like link , basically anyone who uses composer uses PSR-0 and PSR-4.

Another thing, MVC has nothing to do with PHP or Web, MVC is a way to organize things and already existed before the web applications and is not the only type of design pattern that exists.

  

If you look at every framework that exists in popular, which use MVC to organize, each uses the "MVC" in its own distinct way, in fact most frameworks organize following the Model, Controller and View is almost optional in at least one of the cases, so it's up to you to understand that something that is not a "class" can still be MVC.

A detail, even if you want to use .inc , can leave your scripts visible to anyone browsing, since contracted servers and hosts usually do not have such an extension configured to be interpreted as a php script, :

http://site/foo/bar.inc

It will be able to see the source of your file, or anyone can know how your script was done and you can even take advantage of it to get data like bank passwords or find security holes to explore them.

In PSR-0 and PSR-4

The PSR-0 has been discontinued, I recommend only using the PSR-4, in both classes and frameworks are usually within the default folder, and these folders are organized based on the class namespace, see this answer that I cited as an example :

  

I will edit and put more links, there are many things here on the site about it

    
09.03.2017 / 02:52