fix: guard K_CURLOPTS constant to prevent fatal error when not defined#865
Open
WayneRocha wants to merge 1 commit intotecnickcom:mainfrom
Open
fix: guard K_CURLOPTS constant to prevent fatal error when not defined#865WayneRocha wants to merge 1 commit intotecnickcom:mainfrom
WayneRocha wants to merge 1 commit intotecnickcom:mainfrom
Conversation
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.
Background
This fix was identified while investigating a fatal error reported in a real-world production environment where TCPDF is vendored inside Event Tickets Plus (a WordPress plugin by StellarWP) alongside WooCommerce PDF Vouchers.
The affected flow:
The workaround that unblocked the affected site was to manually define
K_CURLOPTSbefore TCPDF executes. This PR makes that workaround unnecessary by fixing the root cause in TCPDF itself.Problem
When TCPDF is used as a vendored dependency with
K_TCPDF_EXTERNAL_CONFIGset totrue, the entiretcpdf_config.phpis skipped. If the external config does not defineK_CURLOPTS, PHP 8+ throws a fatal error at runtime:The guard added in
tcpdf_autoconfig.php(commit aab43ab) does not cover this scenario — whenK_TCPDF_EXTERNAL_CONFIGistrue,tcpdf_autoconfig.phpconstants are also bypassed, soK_CURLOPTSmay never be defined before it is used.Fix
Added a
defined()check at the two points of use insideinclude/tcpdf_static.php— inurl_exists()andfileGetContents()— so thatK_CURLOPTSfalls back to an empty array when not defined, preserving the existingCURLOPT_DEFAULTdefaults:This is the correct place for the guard: defensive at the point of use, guaranteed to execute regardless of which configuration path was taken.
Why not fix it in
tcpdf_config.phportcpdf_autoconfig.php?Both of those files are entirely skipped when
K_TCPDF_EXTERNAL_CONFIGistrue, which is a common pattern for projects that vendor TCPDF and supply their own configuration. The only reliable place to handle a missingK_CURLOPTSis where it is consumed.Changes
include/tcpdf_static.php: 2 lines changed (lines 1860 and 1995) — one inurl_exists(), one infileGetContents()