rgb192
asked on
object is the same as className
<?php
class HelloWorld{
public function sayHelloTo($name){
return 'Hello '.$name;
}
}
$obj=new HelloWorld();
//$reflectionMethod=new ReflectionMethod('HelloWorld','sayHelloTo');
$reflectionMethod=new ReflectionMethod($obj,'sayHelloTo');
echo $reflectionMethod->invoke(new HelloWorld(),'Mike');
please explain why
//$reflectionMethod=new ReflectionMethod('HelloWor
$reflectionMethod=new ReflectionMethod($obj,'say
are the same
ASKER
Ok so in all the examples of php: is 'className' same as $obj?
Or is the reflection documentation saying it will take either
Or is the reflection documentation saying it will take either
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for example of what is in reflection class
You are welcome - thanks for the points.
http://www.php.net/manual/en/reflectionmethod.construct.php
Open in new window
In other words the constructor for the Reflection method can take either- The name of a class
OR
- An already instantiated (object) instance of a class
The commented out line above does the former - it passes the class name in as a string. The ReflectionMethod constructor recognises it is a string and will automatically create an object of that class type.
If it is an object (as in the second line) then it will simply use that object.