OOPs Functions函数详解

首页 / PHP入门教程 / OOPs Functions函数详解

get_class -  通过此操作,无涯教程可以获得对象的类名称。

<?php
	class cls1
	{
		
	}
	$obj=new cls1();
	echo get_class($obj);
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

2. get_class_vars -  用于获取类的所有变量作为Array元素。

<?php
	class cls1
	{
		var $x=100;
		var $y=200;
	}
	print_r(get_class_vars("cls1"));
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

3. get_class_methods  -  将类的所有方法作为数组获取。

<?php
	class cls1
	{
	  function fun1()
	  {
	  }
	  function fun2()
	  {
	  }
	}
	print_r(get_class_methods("cls1"));
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

4. get_declare_classes - 获取当前脚本中的所有声明类以及预定义的类。

<?php
	class cls1
	{
	
	}
	print_r(get_declared_classes());
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

5. get_object_vars  -  将对象的所有变量作为数组获取。

<?php
	class cls1
	{
		var $x=100;
		var $y=200;
	}
	$obj= new cls1();
	print_r(get_object_vars($obj));
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

6. class_exists  -  检查指定的类是否存在。

<?php
	class cls1
	{
		
	}
	echo class_exists("cls1");
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

7. is_subclass_of  -  通过使用此函数,无涯教程可以检查第一类是否为第二类的子类。

<?php
	class cls1
	{
		
	}
	class cls2 extends cls1
	{
	}
	echo is_subclass_of("cls2","cls1");
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

8. method_exists  -  通过使用此函数,可以检查类方法是否存在。

<?php
	class cls1
	{
		function fun1()
		{
		}
	}
	echo method_exists("cls1","fun1");
?>

输出:

Some Helpful Functions in PHP to get the Information About Class and Object

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Go语言从入门到实战 -〔蔡超〕

大规模数据处理实战 -〔蔡元楠〕

玩转webpack -〔程柳锋〕

Swift核心技术与实战 -〔张杰〕

Netty源码剖析与实战 -〔傅健〕

Redis核心技术与实战 -〔蒋德钧〕

大数据经典论文解读 -〔徐文浩〕

超级访谈:对话汤峥嵘 -〔汤峥嵘〕

手把手带你写一个MiniSpring -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)