php / web-php

The www.php.net site
http://www.php.net
Other
835 stars 534 forks source link

Proposal for Standardization of PHP Library Directory Structure #979

Closed de54 closed 4 months ago

de54 commented 5 months ago

Hi, Most PHP developers, when starting a project and requiring a PHP library, include it alongside their project files using Composer or manually. Now consider the following scenario:

1- Developer D1 develops project A1 and includes library files X within their project. 2- Developer D1 then develops project A2 and again includes library files X within their project. 3- Developer D2 develops project A3 and also includes library files X within their project.

As illustrated in the above scenario, library files X are duplicated on the computers of both developer D1 and developer D2. This redundancy is not efficient in software development, especially when it comes to maintaining consistent versions of libraries across projects.

The proposed solution involves establishing a standard directory structure for storing PHP libraries, adhering to the Filesystem Hierarchy Standard (FHS) as a reference. For instance, all PHP library files could be stored in /usr/share/php/libs/<lib-name>/<version> or /usr/share/php/libs/<lib-name>. I invite all PHP developers to adopt this standard and transform it into an international norm. Furthermore, I request PHP to officially recognize this standard and create the corresponding directory upon PHP installation for user convenience.

However, this is not sufficient. It would be even more beneficial if PHP developers, in general, adhere to directory structure standards such as the Filesystem Hierarchy Standard (FHS) for various aspects of their projects. For example, configuration files could be stored in /etc/project-name, log files in /var/log/project-name, temporary files in /tmp/project-name, and data storage files separate from the main source code in /var/lib or within the /home directory. The source code and related files could be stored in /lib.

I urge all PHP developers to adopt these standards and transform them into international norms. I also call upon PHP to officially recognize and incorporate these standards. For instance, in future updates, PHP could introduce a function that eliminates the need to manually include libraries from the /usr/share/php/libs directory. Instead, developers could call the function with the library name and version to invoke the desired library. Example:

import(<lib-name>, <version>, <include-file>);

Usage example:

import("dispatch", "11.0.0", "dispatch.php");

I hope that this standard will be accepted by the PHP community and recognized internationally so that we can effectively organize our projects and put an end to the graveyard of redundant files once and for all.

pronskiy commented 4 months ago

This is a website repository. PHP-FIG would be a better place for such proposals: https://www.php-fig.org/get-involved/

@saundefined, close?