rubenski Posted August 9, 2009 Share Posted August 9, 2009 Hello everyone, I am trying the PHP reflection API and I ran into two questions. I have the following code: $modelReflector = new ReflectionClass('Course'); $methods = $modelReflector->getMethods(); foreach($methods as $key => $value){ echo "method: " . $value->getName() . "<br>"; } This code prints the methods in the Course class. My questions are 1. Why does getMethods() take no value or a 'long' value? Can't I pass in a regex somehow to select only setter methods? 2. I noticed that my editor doesn't know the type (and associated fields and methods) of the $value object in the foreach loop. I know it's an object, I found out that there is a getName() method because php.net says so, but my editor doesn't know it. Is there some way to define the type for an array? Or can I cast value to the appropriate type inside the foreach loop? Thanks! Link to comment https://forums.phpfreaks.com/topic/169505-php-typing-questions-from-a-java-programmer/ Share on other sites More sharing options...
Mark Baker Posted August 9, 2009 Share Posted August 9, 2009 From the comments in the PHP online documentation //The long $filter values!!! ReflectionMethod::IS_STATIC; ReflectionMethod::IS_PUBLIC; ReflectionMethod::IS_PROTECTED; ReflectionMethod::IS_PRIVATE; ReflectionMethod::IS_ABSTRACT; ReflectionMethod::IS_FINAL; //Use them like this $R = new ReflectionClass("MyClass"); //print all public methods foreach ($R->getMethods(ReflectionMethod::IS_PUBLIC) as $m) echo $m->__toString(); Link to comment https://forums.phpfreaks.com/topic/169505-php-typing-questions-from-a-java-programmer/#findComment-894348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.