Open SamLowrie opened 3 years ago
PHPWord works correctly with PHP 5.3+. Add information, if something doesn't work..
When installing via composer 0.18.1, the libraries vendor/laminas/*
are installed and included in the autoloader. At least the file vendor/laminas/laminas-zendframework-bridge/src/Autoloader.php
contains code which does not run in PHP 5.3:
Line 15++: use function ... (>=5.6) Line 49, 114, ...: []-Shortcut operator for array creation (>=5.4)
I had a quick look into the other files from the laminas libraries ... they all seem to have the same problem.
This bug is introduced in 0.18.1 version via PR https://github.com/PHPOffice/PHPWord/pull/2032. Add this to your composer.json to disable unnecessary package, to fix it:
"replace": {
"laminas/laminas-zendframework-bridge": "*"
},
Thanks for the fast answer! 👍
I managed to get it to run, but I also had to remove the laminas-escaper with
"replace": {
"laminas/laminas-zendframework-bridge": "*",
"laminas/laminas-escaper": "*"
}
Now PHPOffice seems to work, not sure where the escaper library is actually needed. I am only using the template part of PHPOffice.
PHPWord using laminas/laminas-escaper library with minimal version 2.2, which is compatible with PHP 5.3, see https://github.com/laminas/laminas-escaper/blob/2.2.10/composer.json#L28
Ah, ok. Then an older version of the laminas escaper library must be installed (2.2), as the latest version also uses array declaration shortcut operators (>=5.4).
I got everything running with php 5.3.x with following composer.json
config:
{
"require": {
"phpoffice/phpword": "^0.18.1",
"laminas/laminas-escaper": "2.2"
},
"replace": {
"laminas/laminas-zendframework-bridge": "*"
}
}
Thanks again for the help.
I have to maintain some outdated PHP 5.x installations. The laminas libraries break the compatibility with PHP 5.x for me, as they require php >=v 7. Requirements for PHP in file README.md should probably be updated.