emeraldinspirations/lib-createconstructcallable

Returns an anonymous callable function referencing the constructor of a class

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/emeraldinspirations/lib-createconstructcallable

1.0.0 2017-09-03 09:09 UTC

This package is not auto-updated.

Last update: 2025-10-08 07:48:13 UTC


README

emeraldinspirations logo

lib-createconstructcallable

A component of emeraldinspiration's library.

Returns an anonymous callable function referencing the constructor of a class

PHP does not yet have a syntax for creating a callable for the constructor of a class. Some workarounds involve using ReflectionClass. (See: https://stackoverflow.com/q/24129450/6699286)

This class provides an alternate option. It creates an anonymous function that fulfills the callable need and runs the relevant constructor.

Installing / Getting started

This project has no dependencies, so can simply be required with composer

composer require emeraldinspirations/lib-createconstructcallable

How to use

<?php

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

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

Licensing

The code in this project is licensed under MIT license.