Page MenuHomePhabricator

replaceAll.php maintenance script error: "Namespace declaration statement has to be the very first statement"
Closed, ResolvedPublicBUG REPORT

Description

When using the maintenace script and multiversion/MWScript it gives a namespace error
We’re using the same multiversion setup provided by wikimedia (https://gerrit.wikimedia.org/r/plugins/gitiles/operations/mediawiki-config/+/refs/heads/master/multiversion/MWMultiVersion.php).

$  sudo php multiversion/MWScript.php extensions/ReplaceText/maintenance/replaceAll.php test Hello --dry-run

What happens?:
It gives me a fatal Error instead of expected results

PHP Fatal error:  Namespace declaration statement has to be the very first statement or after any declare call in the script in /extensions/ReplaceText/maintenance/replaceAll.php on line 31

Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /extensions/ReplaceText/maintenance/replaceAll.php on line 31

What should have happened instead?:
The maintenance script should've just excuted and gave me the result back

Software version (skip for WMF-hosted wikis like Wikipedia):
Version: ReplaceText(REL1_39) 1.7
MediaWiki 1.39.5
php 7.4.3
https://gerrit.wikimedia.org/g/operations/mediawiki-config/

Event Timeline

I've never heard of this error message - could it be due to some PHP setting?

In any case, it should probably be fixed... cc @Hexmode

When the script was written the use case--using the WMF's mwscript--was a bit unusual.

The script is executable so that it can be run without using an explicit "php" prefix. This means that it provides a shebang so that the caller knows to use php to interpret the script.

Given that, in 1.40+, there is a requirement to use run.php, I think the convenience that the shebang provided is becoming a problem.

Change 979953 had a related patch set uploaded (by MarkAHershberger; author: MarkAHershberger):

[mediawiki/extensions/ReplaceText@master] Remove shebang

https://gerrit.wikimedia.org/r/979953

Aklapper renamed this task from When using the maintenace script namespace error to replaceAll.php maintenance script error: "Namespace declaration statement has to be the very first statement".Dec 4 2023, 11:35 PM

Change 979953 merged by jenkins-bot:

[mediawiki/extensions/ReplaceText@master] Remove shebang

https://gerrit.wikimedia.org/r/979953

A bit better search would be for #!/usr/bin instead of /usr/bin/env.