PHP 中的 get_parent_class()函数

首页 / PHP入门教程 / PHP 中的 get_parent_class()函数

get_parent_class() - 语法

get_parent_class ( $object );

它检索对象或类的父类名称。

Sr.No Parameter & Description
1

object(必需)

对象或类名。

链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-function-get-parent-class.html

来源:LearnFk无涯教程网

get_parent_class() - 返回值

它返回当前脚本中已声明类的名称的数组。

get_parent_class() - 示例

<?php
   class f1 {
      function f1() {
         //implements some logic
      }
   }
   
   class child extends f1 {
      function child() {
         echo "I'm " , get_parent_class($this) , "'s son\n";
      }
   }
   
   class child2 extends f1 {
      function child2() {
         echo "I'm " , get_parent_class('child2') , "'s son too\n";
      }
   }
	
   $foo=new child();
   $bar=new child2();
?> 

它将产生以下输出-

I'm f1's son
I'm f1's son too

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

技术教程推荐

Web协议详解与抓包实战 -〔陶辉〕

摄影入门课 -〔小麥〕

NLP实战高手课 -〔王然〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

重学线性代数 -〔朱维刚〕

Django快速开发实战 -〔吕召刚〕

如何成为学习高手 -〔高冷冷〕

数据分析思维课 -〔郭炜〕

程序员职业规划手册 -〔雪梅〕

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