Created
December 10, 2016 20:31
-
-
Save shazarre/aef61894179060761e6b3d6443308b6a to your computer and use it in GitHub Desktop.
Constructor reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Test | |
{ | |
public function __construct($required, $notRequired = "abc") | |
{ | |
} | |
} | |
$reflectionClass = new ReflectionClass(Test::class); | |
$constructor = $reflectionClass->getMethod('__construct'); | |
$parameters = $constructor->getParameters(); | |
foreach ($parameters as $parameter) { | |
$name = $parameter->getName(); | |
$parameter = $parameter->isOptional(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment