Php8 compatibility fixes#411
Open
hupendrad4 wants to merge 11 commits into
Open
Conversation
PHP 8.0 removed support for curly brace syntax to access string offsets.
Replace all occurrences of $var{N} with $var[N] across all PHP files.
Fixes fatal errors on PHP 8.0+ for any code using this deprecated syntax.
PHP 8 throws a TypeError when count() or sizeof() is called on null. PHP 7 silently returned 0. Wrap variable arguments with (array) cast to preserve the PHP 7 behaviour safely on PHP 8+. Affected: all PHP files under lib/ using variable or property-chain arguments to count()/sizeof().
The cast (arrya) is a typo causing a PHP fatal error: undefined constant 'arrya'. This caused HTTP 500 on any XMLRPC API call that invokes getPlatforms(). Changed to correct (array) cast.
PHP 8 removed silent treatment of undefined constants as strings. The expression $ds. lib .$ds used the bare word 'lib' as an undefined constant, which throws an Error in PHP 8. Quoted as 'lib' string.
PHP 8 throws TypeError when count() is called on null. Apply the same (array) cast guard to the bundled XML-RPC IXR library under third_party/ to prevent fatal errors during XMLRPC API operations.
array_keys(null) throws a TypeError in PHP 8. Wrap variable and property-chain arguments with (array) cast across all PHP files in lib/ to safely handle cases where the value may be null.
These methods can return null; array_keys(null) throws TypeError in PHP 8. Cast return values to array before passing to array_keys().
get_builds() can return null when no builds exist for a test plan. array_keys(null) throws TypeError in PHP 8. Cast to array first.
…, planImport Three targeted fixes for locations not covered by the bulk pattern: - requirement_mgr.class.php: array_keys(current($rs)) where $rs may be null - cfieldsTprojectAssign.php: array_keys on dynamic property $argsObj->$serviceInput - planImport.php: array_keys on $linkedVersions array element
When $users is an empty array, the generated SQL becomes IN() which is invalid and causes a database error. Added !empty($users) guard alongside the existing !is_null() check so the query is skipped entirely for empty sets.
…ents When running in Docker or any environment where the app connects via a bridge/proxy IP rather than 'localhost', MySQL user grants using the exact hostname fail with 'Access denied'. Using @'%' allows connections from any host and is standard practice for containerised deployments. Fixes TestLink installation failure in Docker Compose setups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title:
fix(php8): PHP 8 compatibility fixes — count/sizeof/array_keys null safety, typo corrections, SQL guard
Body:
Summary
This PR fixes a series of PHP 8 compatibility issues that cause fatal errors
or broken behaviour when running TestLink 1.9.20 on PHP 8.0+. All fixes were
validated against a running PHP 8.1 + MySQL 8.0 environment (Docker Compose).
Problem
PHP 8 introduced strict type enforcement that breaks several patterns which
were silently tolerated in PHP 7:
count(null)→0TypeErrorfatalsizeof(null)→0TypeErrorfatalarray_keys(null)→[]TypeErrorfatal$var{N}string offsetErrorfatalIn addition, two non-PHP-8 bugs were found and fixed:
(arrya)cast inxmlrpc.class.phpcaused HTTP 500 on all XMLRPCAPI calls invoking
getPlatforms()$usersarray indeleteUserRoles()generatedIN()which isinvalid SQL and crashed the query
Changes
1. Curly brace string offsets → bracket syntax
Files:
third_party/kint/PHP 8.0 removed
$var{N}syntax for string offset access. Replaced alloccurrences with
$var[N].2.
count()/sizeof()null safety —lib/Files: 149 files across
lib/Wrapped variable and property-chain arguments with
(array)cast: