Efficient and safe way to manage numerous PHP “include” file paths?

  Kiến thức lập trình

The thought is that I might have something like 10 “dependency” files that might be included in some files, another 5 dependencies that are included in other types of files, some other files use a mix of these dependencies. If I want to reorganize where these files are located on the server, it would obviously break the application, having all these hard-coded file paths in each, it would be incredibly inefficient to manually update each file with a new path inside each include

For example, say I have a bunch of files that use include('database_control.php'); and include('user_manager.php');, if I decide to move these two files into a library/ directory, I would have to update each file using those includes.

What is the proper way to deal with this problem? I’m trying to be organized here, using classes for maintainability, but it’s not very maintainable if moving a file suddenly severs access to a class within it.

Does it make sense to have a single file “locked” into a certain location on the server, that defines the path to all of these include calls? For example, each file would have include('common_paths.php'); which would have a list of define that lead to each dependency? define('database_controller', 'some/random/path/database_control.php'); is an example of one line, and in the main file that was going to have include('database_control.php'); would instead have include(constant('database_controller');

What is the proper way to go about something like this?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT