mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
PHP 8.0 is now the minimum, so these branches can no longer run:
- functions.php: str_starts_with/str_ends_with/str_contains polyfills;
zm_random_bytes() fallbacks to mcrypt and openssl (random_bytes() is
always there).
- auth.php: the password_hash() check in migrateHash().
- session.php: pre-7.3 setcookie()/session_set_cookie_params() forms
without samesite, and the pre-5.4 is_session_started().
- stream.php: blocking sem_acquire() for PHP < 5.6.1, and the PHP < 5.6
half of the 64 bit event id unpack check (the 32 bit PHP_INT_SIZE half
stays).
- database.php: the magic quotes branch of dbEscape();
get_magic_quotes_gpc() was removed in PHP 8.
- logger.php: the PHP >= 5.2 guards around error_get_last().
- Event.php, ImageComponent.php: the PHP < 4.3.10 sprintf('%.3f').
- image.php: the imagedestroy() branch for PHP < 8.
database.php keeps its PHP_VERSION_ID >= 80100 check, as 8.0 is still
supported.
Tests: tests/php/test_php_minimum.php checks the declared minimum in
composer.json, the platform check, the rpm and deb dependencies, and that
no PHP 4/5/7 version check is left in the web code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.2 KiB
PHP
52 lines
2.2 KiB
PHP
<?php
|
|
// ZoneMinder requires PHP 8.0 or newer: the vendored firebase/php-jwt 7 needs it.
|
|
// This checks that the requirement is declared everywhere it is enforced, and
|
|
// that no PHP 4/5/7 compatibility branch comes back into the web code.
|
|
//
|
|
// Run: php tests/php/test_php_minimum.php
|
|
$root = __DIR__.'/../..';
|
|
|
|
$failures = 0;
|
|
$passes = 0;
|
|
|
|
function check($name, $got, $expected) {
|
|
global $failures, $passes;
|
|
if ($got === $expected) {
|
|
$passes++;
|
|
echo "ok $name\n";
|
|
} else {
|
|
$failures++;
|
|
echo "FAIL $name\n got: ".var_export($got, true)."\n expected: ".var_export($expected, true)."\n";
|
|
}
|
|
}
|
|
|
|
$composer = json_decode(file_get_contents("$root/web/composer.json"), true);
|
|
check('composer.json requires php >=8.0', $composer['require']['php'] ?? null, '>=8.0');
|
|
check('password-compat (a PHP 5.5 polyfill) is not required',
|
|
isset($composer['require']['ircmaxell/password-compat']), false);
|
|
check('composer platform check rejects PHP < 8.0',
|
|
strpos(file_get_contents("$root/web/vendor/composer/platform_check.php"), 'PHP_VERSION_ID >= 80000') !== false, true);
|
|
|
|
check('rpm requires php-common >= 8.0',
|
|
(bool)preg_match('/^Requires: php-common >= 8\.0$/m', file_get_contents("$root/distros/redhat/zoneminder.spec")), true);
|
|
foreach (array('ubuntu2004', 'beowulf') as $distro) {
|
|
check("$distro deb requires php-mysql (>= 2:8.0)",
|
|
strpos(file_get_contents("$root/distros/$distro/control"), 'php-mysql (>= 2:8.0)') !== false, true);
|
|
}
|
|
|
|
// A comparison of the running PHP version against anything below 8 is dead code.
|
|
$old_checks = array();
|
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("$root/web", FilesystemIterator::SKIP_DOTS));
|
|
foreach ($it as $file) {
|
|
$path = substr($file->getPathname(), strlen("$root/"));
|
|
if (substr($path, -4) != '.php' or preg_match('#^web/(vendor|api/lib|api/app/vendor|api/app/Plugin)/#', $path)) continue;
|
|
foreach (file($file->getPathname()) as $n => $line) {
|
|
if (preg_match('/(phpversion\(\)|PHP_VERSION)\s*,\s*[\'"][4-7]\.|PHP_MAJOR_VERSION\s*<\s*8/', $line))
|
|
$old_checks[] = "$path:".($n + 1);
|
|
}
|
|
}
|
|
check('no PHP 4/5/7 version checks in web code', $old_checks, array());
|
|
|
|
echo "\n$passes passed, $failures failed\n";
|
|
exit($failures ? 1 : 0);
|