Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: ReflectionMethod::__construct(): Argument #2 ($method) must be of type ?string, array given #902

Open
Luc45 opened this issue Sep 16, 2024 · 2 comments

Comments

@Luc45
Copy link

Luc45 commented Sep 16, 2024

I'm encountering this error:

Uncaught TypeError: ReflectionMethod::__construct(): Argument #2 ($method) must be of type ?string, array given

Pointing to this line.

I've stumbled upon this error when trying to simulate an error in a context similar to this one:

function foo_init() {
	if ( ! class_exists( 'Foo' ) ) {
		class Foo extends Bar {
			protected function __construct() {
				parent::__construct();

				add_action( 'init', function () {
					if ( rand( 0, 10 ) === 10 ) {
						throw new \RuntimeException( 'Simulated error . ' );
					}
				} );
			}
		}
	}
}

It seems $callback['function'][1] is an array, whereas it should be a string.

This is probably being called in the context of PHP Debug Logger Collector, output_fatal method, while building the stack trace.

Unfortunately I don't have time right now to further debug this. Maybe some kinda of easy defensive programming here could be useful, like a try-catch and skipping the trace if it fails to build it...?

@Luc45
Copy link
Author

Luc45 commented Sep 16, 2024

I forgot to mention that this ran on PHP 8.4 RC.3

@ardittristan
Copy link

a 'quickfix' to combat fatal type errors would be replacing

} catch ( ReflectionException $e ) {
$callback['error'] = new WP_Error( 'reflection_exception', $e->getMessage() );
}

with

		} catch ( ReflectionException $e ) {

			$callback['error'] = new WP_Error( 'reflection_exception', $e->getMessage() );

		} catch ( TypeError $e ) {

			$callback['error'] = new WP_Error( 'type_error', $e->getMessage() );

		}

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

No branches or pull requests

2 participants