diff --git a/src/Internal/DependencyManagement/AbstractServiceProvider.php b/src/Internal/DependencyManagement/AbstractServiceProvider.php index 76a104eeedc..4f932062fdc 100644 --- a/src/Internal/DependencyManagement/AbstractServiceProvider.php +++ b/src/Internal/DependencyManagement/AbstractServiceProvider.php @@ -88,7 +88,7 @@ abstract class AbstractServiceProvider extends \League\Container\ServiceProvider } catch ( \ReflectionException $ex ) { throw new ContainerException( "AbstractServiceProvider::add_with_auto_arguments: error when reflecting class '$class': {$ex->getMessage()}" ); } - } elseif ( ! is_object( $concrete ) && ! is_callable( $concrete ) && ! function_exists( $concrete ) ) { + } elseif ( ! is_object( $concrete ) && ! is_callable( $concrete ) ) { throw new ContainerException( 'AbstractServiceProvider::add_with_auto_arguments: concrete must be a valid class name, function name, object, or callable.' ); } diff --git a/src/Proxies/LegacyProxy.php b/src/Proxies/LegacyProxy.php index 9584dc2f3e3..c110b686f92 100644 --- a/src/Proxies/LegacyProxy.php +++ b/src/Proxies/LegacyProxy.php @@ -49,7 +49,7 @@ class LegacyProxy { // If the class is a singleton, use the "instance" method. if ( method_exists( $class_name, 'instance' ) ) { - return $class_name::instance( $args ); + return $class_name::instance( ...$args ); } // Fallback to simply creating a new instance of the class. diff --git a/tests/php/src/Internal/DependencyManagement/ExampleClasses/ClassWithSingleton.php b/tests/php/src/Internal/DependencyManagement/ExampleClasses/ClassWithSingleton.php new file mode 100644 index 00000000000..44205c8009e --- /dev/null +++ b/tests/php/src/Internal/DependencyManagement/ExampleClasses/ClassWithSingleton.php @@ -0,0 +1,39 @@ +sut->get_instance_of( \WooCommerce::class ); - $instance2 = $this->sut->get_instance_of( \WooCommerce::class ); - $this->assertSame( \WooCommerce::instance(), $instance1 ); - $this->assertSame( $instance1, $instance2 ); + // ClassWithSingleton is in the root namespace and thus can't be autoloaded. + require_once dirname( __DIR__ ) . '/Internal/DependencyManagement/ExampleClasses/ClassWithSingleton.php'; + + $instance = $this->sut->get_instance_of( \ClassWithSingleton::class, 'foo', 'bar' ); + $this->assertSame( \ClassWithSingleton::$instance, $instance ); + $this->assertEquals( array( 'foo', 'bar' ), \ClassWithSingleton::$instance_args ); } /**