Home  >  Article  >  Backend Development  >  PHP get_class_methods function usage_PHP tutorial

PHP get_class_methods function usage_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:051159browse

PHP get_class_methods function usage

The function of get_class_methods function is to return an array composed of the method names of the class. This article will briefly share the related usage of this function.

Function prototype array get_class_methods (mixed $class_name)

Returns an array consisting of method names defined in the class specified by class_name. If an error occurs, NULL is returned.

Note: Starting with PHP 4.0.6, it is possible to specify the object itself instead of class_name. Specific examples of use of get_class_methods() are as follows:

<?php
class myclass {
	// constructor
	function myclass() {
		return(true);
	}
	// method 1
	function myfunc1() {
		return(true);
	}
	// method 2
	function myfunc2() {
		return(true);
	}
}
$class_methods = get_class_methods('myclass');
// or
$class_methods = get_class_methods(new myclass());

foreach ($class_methods as $method_name) {
	echo $method_name,'<br />';
}

The above example will output:

myclass
myfunc1
myfunc2

Note:

Since PHP 5, this function returns the method's defined name (case-sensitive). In PHP 4 always returns lowercase.

Articles you may be interested in

  • php uses the session_set_save_handler() function to save the session to the MySQL database
  • The role and usage of the php get_headers function
  • php simulates get_headers function
  • Comparison of file_get_contents and curl performance efficiency in PHP
  • phpMyAdmin Cannot start session without errors error solution
  • php get_headers determines whether the URL is Valid
  • Function to obtain subclass_id collection
  • php mktime function analysis

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/906826.htmlTechArticlePHP get_class_methods function usage get_class_methods function is to return an array composed of the method names of the class. This article will briefly share the related usage of this function. Function...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn