-2
I’m developing a applying with Friendly URL’s and there comes a time when I can’t find a way out.
I got the following:
$constructParams = [];
$reflectionClass = new \ReflectionClass($controller);
$construct = $reflectionClass->getConstructor();
if (isset ( $construct ) ){
foreach( $construct->getParameters() as $parameter){
$class = $parameter->getClass();
$constructParams[$parameter->name] = $class
? new $class->name
: $parameter->name;
}
}
$instance = $reflectionClass->newInstanceArgs($constructParams);
That one code instance one class and populace your builder.
My difficulty is that if any constructor parameter (if any) is a object of a class, the problem will be solved by:
$parameter->getClass();
however, if that parameter (that will always be typed), for a int, bool, float or other thing, I can’t determine your type.
Example:
public function __construct (Classe $classe, int idade)
I’ve searched everything but found nothing!
In time: If I don’t guy the parameters that NAY sane objects, all works well.
But the goal is type.
Until you offer a reply see if this is what you’re looking for: https://repl.it/repls/CadetbluePuzzlingTrigger
– Augusto Vasques
No friend. There you did straight! Need to use Reflectionclass because I will only release the types in the builder. But when I check the received parameters, each of them comes from a Class object that is the return of Reflectionclass.
– Carlos Rocha
I’m sorry if I didn’t make myself clear. I meant by example is that the
ReflectionClass
does not work with primitive types(integer
,boolean
,string
,... ) this class only works with derivative types ofobject
then it is necessary to filter what will instantiate withReflectionClass
.– Augusto Vasques