PHP Reflection - Get Method Parameter Type As String

后端 未结 6 1876
無奈伤痛
無奈伤痛 2020-12-01 18:44

I\'m trying to use PHP reflection to dynamically load the class files of models automatically based upon the type of parameter that is in the controller method. Here\'s an e

6条回答
  •  醉话见心
    2020-12-01 19:29

    This is a better regular expression than the one from that answer. It will work even when the parameter is optional.

    preg_match('~>\s+([a-z]+)\s+~', (string)$ReflectionParameter, $result);
    $type = $result[1];
    

提交回复
热议问题