как получить тип свойства объекта doctrine

На самом деле у меня есть объект доктрины, который мне нужно, чтобы заполнить его prperties динамически.

Я хотел бы сделать что-то вроде этого:

$entity = new Entity(); $reflect = new ReflectionClass($entity); // $fields is an array whihch contain the entity name as the array key and the value as the array value foreach ($fields as $key => $val) { if (!reflect->hasProperty($key)) { var_dump('the entity does not have a such property'); continue; } if ( the type of $key is string ) { // convert $value to utf8 } elseif ( the type of $key is integer) { // do something else } //....etc } 

Как мне это сделать?

Нашел решение благодаря @Yoshi. Надеюсь, это поможет

использовать Doctrine \ Common \ Annotations \ AnnotationReader;

 $docReader = new AnnotationReader(); $entity = new Entity(); $reflect = new ReflectionClass($entity); // $fields is an array whihch contain the entity name as the array key and the value as the array value foreach ($fields as $key => $val) { if (!reflect->hasProperty($key)) { var_dump('the entity does not have a such property'); continue; } $docInfos = $docReader->getPropertyAnnotations($reflect->getProperty($key)); if ( $docInfos[0]->type === 'string' ) { // convert $value to utf8 } elseif ( $docInfos[0]->type === 'integer' ) { // do something else } //....etc } 

Вы можете использовать gettype

 $entity = new Entity(); $reflect = new ReflectionClass($entity); // $fields is an array whihch contain the entity name as the array key and the value as the array value foreach ($fields as $key => $val) { if (!reflect->hasProperty($key)) { var_dump('the entity does not have a such property'); continue; } if ( gettype($key) === "integer" ) { // convert $value to utf8 } elseif ( gettype($key) === "string") { // do something else } //....etc }