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

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

技术教程推荐

快速上手Kotlin开发 -〔张涛〕

架构实战案例解析 -〔王庆友〕

后端存储实战课 -〔李玥〕

Kafka核心源码解读 -〔胡夕〕

跟月影学可视化 -〔月影〕

Go 语言项目开发实战 -〔孔令飞〕

深入C语言和程序运行原理 -〔于航〕

云计算的必修小课 -〔吕蕴偲〕

PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕

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