Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Difference between "const" and "define()": http://stackoverflow.com/a/3193704/246724
- define(): Run-time constant.
- const: Compile-time constant. Declaration cannot use dynamic expressions.
There is a number of places in Drupal where we define DRUPAL_ROOT. bootstrap.inc, scripts, tests.
Proposal:
- Have a separate file for define() stuff, esp. DRUPAL_ROOT.
- Include this file from autoload.php (by mentioning it in composer.json).
- Constants defined with "const" can either move to this file or be turned into class constants like Drupal::MINIMUM_PHP.
- const and define() in modules are out of scope for this issue.
This will open the door for other changes in future issues:
- Scripts (core/scripts/*) can include autoload.php and no longer need to define DRUPAL_ROOT.
- Scripts logic can be moved to classes, e.g. in Drupal\Core\Scripts\..
This might not work for all scripts, but some or most of them. - There can be shared logic for dealing with script arguments and options, similar to drush.
This logic could even come from a 3rd party, e.g. Aura.Cli
I came across this while working on the switch-psr4.sh script in #2083547: PSR-4: Putting it all together.
Thoughts?
Comments
Comment #1
donquixote CreditAttribution: donquixote commentedChanges to issue summary:
- Cmd logic could come from a 3rd party, e.g. Aura.Cli.
- const and define() in modules are out of scope for this issue.
Comment #10
joachim CreditAttribution: joachim as a volunteer commentedPossibly a duplicate of #1792310: Wrong DRUPAL_ROOT with non-standard code structure?