Skip to content

Throw a QueryPath\Exception from filterLambda()/eachLambda() on PHP 8 - #110

Merged
jakejackson1 merged 2 commits into
mainfrom
fix/issue-81
Oct 26, 2026
Merged

jakejackson1 merged 2 commits into
mainfrom
fix/issue-81

Conversation

@gravitypdf-bot

Copy link
Copy Markdown
Contributor

filterLambda() and eachLambda() call create_function(), which was removed in PHP 8.0, so on PHP 8+ they die with an Error that doesn't name a replacement:

qp($xml, 'a')->filterLambda('return true;');
// Before: Error: Call to undefined function QueryPath\Helpers\create_function()
// After:  QueryPath\Exception: filterLambda() requires create_function(), which was removed in PHP 8.0. Use filterCallback() with a closure instead.

Changes

  • Both methods check function_exists('create_function') before doing anything and, when it's missing, throw a QueryPath\Exception that names the replacement (filterCallback() / each()). Nothing changes on PHP 7.1–7.4.
  • The @deprecated docblocks now say that the methods only work on PHP 7 and will be removed in 5.0.
  • CHANGELOG entry.

Tests

DOMQueryTest::testFilterLambda and testEachLambda are no longer skipped unconditionally. Where create_function() exists they assert the old results; where it doesn't, they expect the new exception and message. Both fail on PHP 8.5 without the fix (an Error is thrown instead). The PHP 7.4 path was checked by hand, because the local vendor/ is built for PHP 8; CI covers 7.1–7.4.

Behaviour change: on PHP 8+ the thrown type goes from Error to QueryPath\Exception, so these calls can now be caught with catch (QueryPath\Exception $e).

Fixes #81.

🤖 Generated with Claude Code

gravitypdf-bot and others added 2 commits October 26, 2026 11:21
create_function() was removed in PHP 8.0, so both methods failed with an
Error about an undefined function. They now throw an exception naming
filterCallback() / each() as the replacement, and keep working on PHP 7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.76%. Comparing base (6ae6acf) to head (c758356).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #110      +/-   ##
============================================
+ Coverage     90.69%   90.76%   +0.07%     
- Complexity     1424     1426       +2     
============================================
  Files            25       25              
  Lines          3170     3174       +4     
============================================
+ Hits           2875     2881       +6     
+ Misses          295      293       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jakejackson1 jakejackson1 added the bug Something isn't working label Oct 26, 2026
@jakejackson1
jakejackson1 merged commit b41810e into main Oct 26, 2026
14 checks passed
@jakejackson1
jakejackson1 deleted the fix/issue-81 branch October 26, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filterLambda() and eachLambda() are non-functional on PHP 8 — they call the removed create_function()

2 participants