Skip to content

Instantly share code, notes, and snippets.

@shazarre
Created December 10, 2016 20:31
Show Gist options
  • Save shazarre/aef61894179060761e6b3d6443308b6a to your computer and use it in GitHub Desktop.
Save shazarre/aef61894179060761e6b3d6443308b6a to your computer and use it in GitHub Desktop.
Constructor reflection
<?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