Skip to content

fix: fatal error when using an undefined combo parameter name#34

Open
peterschade wants to merge 2 commits into
Skrol29:masterfrom
peterschade:fix/combo-static-this-error
Open

fix: fatal error when using an undefined combo parameter name#34
peterschade wants to merge 2 commits into
Skrol29:masterfrom
peterschade:fix/combo-static-this-error

Conversation

@peterschade

Copy link
Copy Markdown

Problem

meth_Misc_ApplyPrmCombo is declared static but its error branch calls $this->meth_Misc_Alert(). In PHP 8 this causes a fatal error whenever a template references an undefined combo name:

Fatal error: Uncaught Error: Using $this when not in object context
  in tbs_class.php:4202

Minimal reproduction:

$tbs = new clsTinyButStrong;
$tbs->Source = '[onshow.msg;combo=undefined_combo]';
$msg = 'hello';
$tbs->Show(TBS_NOTHING); // Fatal error on PHP 8

Fix

Add an optional $TBS = null parameter to meth_Misc_ApplyPrmCombo and pass $this from the merge-time call site (meth_Locator_FindTbs). The registration-time call site (f_Misc_UpdateArray, always called with $Loc=false) stays without $TBS, so missing combos at combo-definition time are silently skipped — correct behaviour since combos can be registered in any order.

Changes

  • tbs_class.php: 3-line fix in meth_Misc_ApplyPrmCombo
  • testunit/testcase/PrmComboTestCase.php: new unit test case with two tests
    • testKnownCombo — verifies a registered combo's parameters are applied
    • testUnknownComboRaisesTbsError — reproduces the bug; passes only after the fix
  • testunit/index.php: registers the new test case

meth_Misc_ApplyPrmCombo is a static method but called $this->meth_Misc_Alert()
in its error branch, causing a fatal "Using $this when not in object context"
in PHP 8 whenever a template referenced an unknown combo name.

Fix: add an optional $TBS parameter and pass $this from the instance call site
(line 1436). The registration-time call site (line 4260, $Loc=false) stays
without $TBS, so missing combos at registration time are silently skipped —
correct behaviour since combos can be registered in any order.

Adds PrmComboTestCase with two unit tests that reproduce the bug and verify
the fix.
@Skrol29

Skrol29 commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Thanks, very well documented and the idea of the optional argument is good.
The fix is nice but the new UnitTest fails, I'm going to look into it.

TBS resolves field names via VarRef/$GLOBALS, not the local scope of a
class method. Replace the local $msg assignment with VarRef so the tag
[onshow.msg;...] is actually resolved during Show().

Also remove an unused $this->newInstance assignment from the second test.
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.

2 participants