In PHP Judy 2.2.0, the Judy::next() method has been renamed to Judy::searchNext() to resolve naming conflicts with the new Iterator interface implementation.
Before (PHP Judy 2.1.0 and earlier):
$judy = new Judy(Judy::INT_TO_INT);
$judy[100] = 1;
$judy[200] = 2;
$judy[300] = 3;
// Find next index after 150
$next_index = $judy->next(150); // Returns 200After (PHP Judy 2.2.0):
$judy = new Judy(Judy::INT_TO_INT);
$judy[100] = 1;
$judy[200] = 2;
$judy[300] = 3;
// Find next index after 150
$next_index = $judy->searchNext(150); // Returns 200The Judy::next() method conflicted with the Iterator::next() method required by PHP's Iterator interface. To properly implement the Iterator interface (fixing GitHub issue #25), we needed to resolve this naming conflict.
- Search your codebase for all occurrences of
$judy->next( - Replace
$judy->next(with$judy->searchNext( - Test your application to ensure functionality remains the same
// Old code
$index = 100;
while ($index !== null) {
echo "Found index: $index\n";
$index = $judy->next($index);
}
// New code
$index = 100;
while ($index !== null) {
echo "Found index: $index\n";
$index = $judy->searchNext($index);
}With this change, Judy objects now properly implement the Iterator interface:
$judy = new Judy(Judy::INT_TO_INT);
$judy[1] = 'one';
$judy[2] = 'two';
$judy[3] = 'three';
// Now works with foreach
foreach ($judy as $key => $value) {
echo "$key => $value\n";
}
// Works with SPL iterators
$limited = new LimitIterator($judy, 0, 2);
foreach ($limited as $key => $value) {
echo "$key => $value\n";
}
// Works with instanceof checks
if ($judy instanceof Iterator) {
echo "Judy implements Iterator interface!\n";
}- All other Judy methods remain unchanged
- Functionality is identical - only the method name changed
- Performance characteristics are the same
- Memory usage is unchanged
After updating your code, run your test suite to ensure everything works correctly. The Judy extension includes comprehensive tests that verify the new searchNext() method works exactly like the old next() method.
If you encounter any issues during migration, please:
- Check that all
$judy->next(calls have been updated to$judy->searchNext( - Verify that your Judy objects are being used correctly with the new Iterator interface
- Run the test suite to ensure compatibility
- Open an issue on GitHub if you need additional assistance