Skip to content

Conversation

@samford
Copy link

@samford samford commented Feb 28, 2025

Implicit nullable parameter declarations are deprecated in PHP 8.4, so the following output appears when using SimpleXLSX with PHP 8.4:

Deprecated: Shuchkin\SimpleXLSXEx::getColorValue(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in src/SimpleXLSXEx.php on line 614

This updates the type of the getColorValue function's $a parameter to be
explicitly nullable.

It's worth noting that nullable type declarations were introduced in PHP 7.1, so this is only a solution if your PHP target is at or above 7.1. [For what it's worth, PHP 7.1 has been unsupported (EOL) since 2019-12-01.]

Implicit nullable parameter declarations are deprecated in PHP 8.4,
so the following output appears when using SimpleXLSX with PHP 8.4:

`Deprecated: Shuchkin\SimpleXLSXEx::getColorValue(): Implicitly
marking parameter $a as nullable is deprecated, the explicit nullable
type must be used instead in src/SimpleXLSXEx.php on line 614`

This updates the type of the `getColorValue` function's `$a`
parameter to be explicitly nullable.
@ValentinPeltier
Copy link

ValentinPeltier commented Dec 4, 2025

@shuchkin Can you please merge this? It whould be very helpful.

Thank you very much for your work

@shuchkin
Copy link
Owner

shuchkin commented Dec 4, 2025

Valentin, we support PHP 5.5+, "?Class $arg" supported from 7.1
I've changed signature to actual public function getColorValue(SimpleXMLElement $a) in 1.1.15
thx

@shuchkin shuchkin closed this Dec 4, 2025
@samford
Copy link
Author

samford commented Dec 4, 2025

@shuchkin Thank you for your attention on this. I tested 1.1.15 and unfortunately the implementation you mentioned leads to an error because other SimpleXLSX functions can pass null values to getColorValue(). I encountered this when using rowsEx() and you can easily replicate this issue by running examples/02-rows_and_rowsEx.php:

Fatal error: Uncaught TypeError: Shuchkin\SimpleXLSXEx::getColorValue(): Argument #1 ($a) must be of type SimpleXMLElement, null given, called in /vendor/shuchkin/simplexlsx/src/SimpleXLSXEx.php on line 222 and defined in /vendor/shuchkin/simplexlsx/src/SimpleXLSXEx.php:625
Stack trace:
#0 /vendor/shuchkin/simplexlsx/src/SimpleXLSXEx.php(222): Shuchkin\SimpleXLSXEx->getColorValue(NULL)
#1 /vendor/shuchkin/simplexlsx/src/SimpleXLSXEx.php(118): Shuchkin\SimpleXLSXEx->readBorders()
#2 /vendor/shuchkin/simplexlsx/src/SimpleXLSX.php(1066): Shuchkin\SimpleXLSXEx->__construct(Object(Shuchkin\SimpleXLSX))
#3 /vendor/shuchkin/simplexlsx/src/SimpleXLSX.php(1054): Shuchkin\SimpleXLSX->readRowsEx(0, 0)
#4 /vendor/shuchkin/simplexlsx/examples/02-rows_and_rowsEx.php(22): Shuchkin\SimpleXLSX->rowsEx()
#5 {main}
  thrown in /vendor/shuchkin/simplexlsx/src/SimpleXLSXEx.php on line 625

For the change in 1.1.15 to work without errors, it appears that you will need to account for null values before calling getColorValue() (i.e., to make sure you never pass it null). If getColorValue() is intended as a function that users may also call, this seems like a step backward in terms of usability, as users will need to add similar logic to avoid passing a null value and this will break existing scripts. That said, I can understand if this is the only approach that will work for your minimum PHP target.

@shuchkin
Copy link
Owner

shuchkin commented Dec 4, 2025

oops

fixed

@samford
Copy link
Author

samford commented Dec 4, 2025

Thanks! I confirmed that the affected example and my related scripts using rowsEx() work as expected when using the re-release of 1.1.15. I don't see any deprecation warning (as in the original PR description) when using PHP 8.5, so this resolves my initial issue.

@shuchkin For what it's worth, I would highly recommend against re-tagging a version that has already been published like this. In my experience, it's always better to fix forward by releasing a new version (e.g., 1.1.16), as it avoids potential downstream issues.

It seems that Composer [2.9.2] may handle this situation properly but it's best not to rely on that (e.g., I manually modified my composer.lock file to reference the initial 1.1.15 commit and composer update noticed the commit hash mismatch and updated the lock file and vendored files). If it didn't (or a user isn't using Composer), anyone who updated to 1.1.15 before the fix was published may not receive it (i.e., 1.1.15 == 1.1.15). It was a relatively short window of time but releasing a new version (1.1.16) is the safest route.

@shuchkin
Copy link
Owner

shuchkin commented Dec 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants