Skip to content

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

Description

@jakejackson1

Guidelines

Description of the bug

filterLambda() and eachLambda() are both built on create_function(), which was deprecated in PHP 7.2 and removed in PHP 8.0. Every call on PHP 8 raises:

Error: Call to undefined function QueryPath\Helpers\create_function()

src/Helpers/QueryFilters.php:104 and :377:

$function = create_function('$index, $item', $fn);
...
$fn = create_function('$index, &$item', $lambda);

Since the library supports PHP 7.1–8.5 and the majority of that range cannot run these methods at all, they are dead API surface on every current install. The test suite already acknowledges this — DOMQueryTest::testFilterLambda and testEachLambda are skipped with the message create_function removed in PHP8.0, so the suite reports 2 skips on every modern run.

Suggested resolution

They are already marked @deprecated, so the question is only how to retire them:

  • Now (non-breaking): have them throw a clear QueryPath\Exception pointing at filterCallback() / each(), instead of a raw Error about an undefined function. Anyone hitting this on PHP 8 currently gets a message that does not name a replacement.
  • In 5.0: remove both methods, and with them the two permanently-skipped tests.

I have documented them as non-functional in the meantime rather than presenting them as working API.

There is no workaround — filterCallback() and each() with a closure are the replacements, and have been since PHP 5.3.

QueryPath version

4.2.0 (also reproduces on main at bed5d2c)

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

PHP 8.3.16 CLI (macOS, Homebrew). Affects PHP 8.0 and later; create_function() is deprecated but functional on PHP 7.2–7.4.

Minimal reproducible PHP+HTML snippet to replicate bug

<?php
require __DIR__ . '/vendor/autoload.php';

$xml = '<?xml version="1.0"?><root><a/></root>';

qp($xml, 'a')->filterLambda('return true;');
// Fatal error: Uncaught Error: Call to undefined function QueryPath\Helpers\create_function()

qp($xml, 'a')->eachLambda('return true;');
// Same

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions