PHP | ReflectionMethod getPrototype() Function

The ReflectionMethod::getPrototype() function is an inbuilt function in PHP which is used to return the prototype of the specified method otherwise, an exception/error is returned if the method does not have a prototype.
Syntax:
ReflectionMethod ReflectionMethod::getPrototype( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the prototype of the specified method otherwise, an exception/error is returned if the method does not have a prototype.
Below programs illustrate the ReflectionMethod::getPrototype() function in PHP:
Program 1:
| <?php   // Initializing a user-defined class Department1 classDepartment1 {       publicfunctionMarketing_Dpt() {         return'Department1';     } }   // Initializing a subclass of the above class Department1 classDepartment2 extendsDepartment1{       publicfunctionMarketing_Dpt() {         return'Department2';     }   }  // Again Initializing a subclass of the above subclass Department2 classDepartment3 extendsDepartment2{       publicfunctionCoding_Dpt() {         return'Department3';     }   }   // Using the ReflectionMethod() over the above  // subclass Department2 $A= newReflectionMethod('Department3', 'Marketing_Dpt');   // Calling the getPrototype() function $B= $A->getPrototype();   // Getting the prototype  var_dump($B); ?>  | 
Output:
object(ReflectionMethod)#2 (2) {
  ["name"]=>
  string(13) "Marketing_Dpt"
  ["class"]=>
  string(11) "Department1"
}
Program 2:
| <?php  // Initializing a user-defined class classCompany {      protectedfunctionzambiatek($name) {         return'GFG'. $name;     } }  // Using ReflectionMethod() over the class Company $A= newReflectionMethod('Company', 'zambiatek');  // Calling the getPrototype() function $B= $A->getPrototype();  // Getting the prototype or an error is returned // if the method does not have a prototype. var_dump($B); ?>  | 
Output: Method does not have any prototype that will give you an error.
PHP Fatal error: Uncaught ReflectionException: Method Company::
zambiatek does not have a prototype in 
/home/9d8367b263ee4d7ec6941876b0eae792.php:15
Stack trace:
#0 /home/9d8367b263ee4d7ec6941876b0eae792.php(15): 
ReflectionMethod->getPrototype()
#1 {main}
  thrown in /home/9d8367b263ee4d7ec6941876b0eae792.php on line 15
Reference: https://www.php.net/manual/en/reflectionmethod.getprototype.php
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


