Opened 3 years ago
Last modified 2 weeks ago
#60077 assigned defect (bug)
Class UnexpectedValueException not found
| Reported by: | vikram6 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Database | Version: | 6.4.2 |
| Severity: | critical | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
I'm seeing the following error when running certain wp cli commands -
PHP Fatal error: Uncaught Error: Class "WpOrg\Requests\UnexpectedValueException" not found in wp-includes/Requests/src/Iri.php:726
I believe this bug was introduced recently in this commit - https://core.trac.wordpress.org/changeset/56835. UnexpectedValueException is missing the backslash \ and hence PHP is trying to find it in the WpOrg\Requests namespace instead of the global namespace. The lines of code that are referencing UnexpectedValueException should be updated to the following -
throw new \UnexpectedValueException();
Full stack trace -
PHP Fatal error: Uncaught Error: Class "WpOrg\Requests\UnexpectedValueException" not found in wp-includes/Requests/src/Iri.php:726
Stack trace:
#0 [internal function]: WpOrg\Requests\Iri->__wakeup()
#1 phar:///usr/share/wp-cli.phar/vendor/wp-cli/search-replace-command/src/WP_CLI/SearchReplacer.php(86): unserialize()
#2 phar:///usr/share/wp-cli.phar/vendor/wp-cli/search-replace-command/src/WP_CLI/SearchReplacer.php(57): WP_CLI\SearchReplacer->run_recursively()
#3 phar:///usr/share/wp-cli.phar/vendor/wp-cli/search-replace-command/src/Search_Replace_Command.php(580): WP_CLI\SearchReplacer->run()
#4 phar:///usr/share/wp-cli.phar/vendor/wp-cli/search-replace-command/src/Search_Replace_Command.php(400): Search_Replace_Command->php_handle_col()
#5 [internal function]: Search_Replace_Command->__invoke()
#6 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func()
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}()
#8 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(491): call_user_func()
#9 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(417): WP_CLI\Dispatcher\Subcommand->invoke()
#10 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(440): WP_CLI\Runner->run_command()
#11 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1237): WP_CLI\Runner->run_command_and_exit()
#12 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#13 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process()
#14 phar:///usr/share/wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#15 phar:///usr/share/wp-cli.phar/php/boot-phar.php(11): include('...')
#16 /usr/share/wp-cli.phar(4): include('...')
#17 {main}
More details -
- WordPress version - 6.4.2
- WP CLI command -
wp search-replace foo bar --regex --skip-plugins --skip-themes - The database needs to have a certain format of serialized data to reproduce this but I'm not exactly sure what that format is.
Change History (2)
This ticket was mentioned in PR #14842 on WordPress/wordpress-develop by @nofearinc.
2 weeks ago
#1
- Keywords has-patch has-unit-tests added
#2
@
2 weeks ago
Still present in trunk: Iri::__wakeup() throws UnexpectedValueException without a leading backslash inside namespace WpOrg\Requests, so PHP fails with "Class not found" instead. The __wakeup() guards are core-only ([56835]; upstream Requests has none), so the fix belongs in core. Hooks and Session already throw \LogicException.
Patch with a unit test: https://github.com/WordPress/wordpress-develop/pull/14842
This seems to fit the HTTP API component better than Database.
AI assistance: Claude Code (Claude Opus 5.5) for confirming the bug and drafting the fix and test; reviewed and tested by me.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
WpOrg\Requests\Iri::__wakeup()is declared innamespace WpOrg\Requestsand throwsnew UnexpectedValueException()without a leading backslash. PHP then looks forWpOrg\Requests\UnexpectedValueExceptionand throws anError("Class not found") instead, which acatch ( Exception $e )aroundunserialize()does not catch.The
__wakeup()methods were added to the bundled Requests classes in [56835] and are not part of the upstream library (checked v2.0.17 and develop), so the fix belongs in core.Iriis the only one affected:HooksandSessionalready throw\LogicException.Testing
vendor/bin/phpunit --filter Tests_HTTP_RequestsIrifails without the patch withClass "WpOrg\Requests\UnexpectedValueException" not foundand passes with it.vendor/bin/phpunit --group http --exclude-group external-httppasses.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: confirming the bug in trunk, drafting the fix and test, and running them. I reviewed every line.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code