emeraldinspirations/lib-createconstructcallable

返回一个引用类构造函数的匿名可调用函数

1.0.0 2017-09-03 09:09 UTC

This package is not auto-updated.

Last update: 2024-09-25 02:56:55 UTC


README

emeraldinspirations logo

lib-createconstructcallable

emeraldinspirationlibrary组件。

返回一个引用类构造函数的匿名可调用函数

PHP还没有为创建类构造函数的可调用语法。一些解决方案涉及使用ReflectionClass。 (参见:https://stackoverflow.com/q/24129450/6699286)

此类提供了一个替代方案。它创建一个匿名函数,满足可调用需求并运行相关的构造函数。

安装/入门

该项目没有依赖项,所以可以用composer直接要求。

composer require emeraldinspirations/lib-createconstructcallable

如何使用

<?php

$Callable = ConstructCallableCreator::createConstructCallable(
    ExampleClass::class
);

$NewClass = $Callable($Param1, $Param2);
//Same result as new ExampleClass($Param1, $Param2)

许可

此项目的代码在MIT许可下。