Skip to content

Fix null array offset in _destroy() for PHP 8.5#853

Open
kolotov wants to merge 1 commit intotecnickcom:mainfrom
kolotov:fix/null-file-id-destroy-php85
Open

Fix null array offset in _destroy() for PHP 8.5#853
kolotov wants to merge 1 commit intotecnickcom:mainfrom
kolotov:fix/null-file-id-destroy-php85

Conversation

@kolotov
Copy link

@kolotov kolotov commented Feb 13, 2026

In PHP 8.5, using null as an array offset is deprecated.
The _destroy() method accesses self::$cleaned_ids[$this->file_id]
without checking if $this->file_id is null, triggering a deprecation warning.

Add an early return when $this->file_id is null.

Fixes: #852

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@williamdes williamdes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is correct, there is more code that should maybe be executed

@kolotov
Copy link
Author

kolotov commented Feb 13, 2026

You're right. I'll think about it some more.

@renanrodrigo
Copy link

As this is just about unsetting destroyall when the file has already been cleaned, it's enough to check if there is any file_id at all. If it's null, the second part of the method can still unset the other properties if destroyall is set.

--- a/tcpdf.php
+++ b/tcpdf.php
@@ -7882,7 +7882,7 @@
 	 * @since 4.5.016 (2009-02-24)
 	 */
 	public function _destroy($destroyall=false, $preserve_objcopy=false) {
-		if (isset(self::$cleaned_ids[$this->file_id])) {
+		if (isset($this->file_id) && isset(self::$cleaned_ids[$this->file_id])) {
 			$destroyall = false;
 		}
 		if ($destroyall AND !$preserve_objcopy && isset($this->file_id)) {

@kolotov kolotov force-pushed the fix/null-file-id-destroy-php85 branch from deca36a to 5342602 Compare February 18, 2026 13:17
@kolotov
Copy link
Author

kolotov commented Feb 18, 2026

@renanrodrigo Good point, I have applied your suggested change.

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.

PHP 8.5 deprecation: null array offset in _destroy() when file_id is null

4 participants

Comments