Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ReflectionMethod Constructor With A Single Argument Is Deprecated

ReflectionMethod::__construct() accepted two call shapes: two arguments, new ReflectionMethod($classOrObject, $methodName), or a single string combining both as "Class::method". PHP 8.3 added ReflectionMethod::createFromMethodName() as a dedicated factory method for that single-string form. Until PHP 8.4, calling the constructor with just the combined string was completely silent. In PHP 8.4, it emits a deprecation notice in favor of the new factory method; the object it constructs, and the rest of the Reflection API, are unaffected.

PHP code

<?php

$m = new ReflectionMethod('DateTime::format');
echo $m->getName(), "\n";

Before

format

After

PHP Deprecated:  Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in /codes/reflectionMethodConstructorOneArgDeprecated.php on line 3

Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in /codes/reflectionMethodConstructorOneArgDeprecated.php on line 3
format

PHP version change

This behavior was deprecated in 8.4.

This behavior changed in .

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat