PHP 中的 get_class_vars()函数

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

get_class_vars() - 语法

get_class_vars ( $class_name );

此函数获取给定类的默认属性。返回类的默认公共属性的关联数组。

Sr.No Parameter & Description
1

class_name(必需)

类名。

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

来源:LearnFk无涯教程网

get_class_vars() - 返回值

它返回类的默认公共属性的关联数组。得到的数组元素的形式为varname=>value。

get_class_vars() - 示例

<?php
   class helloworld {
      var $var1;
      var $var2="xyz";
      var $var3=100;
      private $var4; //PHP 5
      
      function helloworld() {
         $this->var1="foo";
         $this->var2="bar";
         return true;
      }
   }
	
   $hello_class=new helloworld();
   $class_vars=get_class_vars(get_class($hello_class));
   
   foreach ($class_vars as $name => $value) {
      echo "$name : $value\n";
   }
?> 

它将产生以下输出-

var1 :
var2 : xyz
var3 : 100

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

技术教程推荐

人工智能基础课 -〔王天一〕

程序员进阶攻略 -〔胡峰〕

NLP实战高手课 -〔王然〕

系统性能调优必知必会 -〔陶辉〕

跟着高手学复盘 -〔张鹏〕

手把手带你搭建秒杀系统 -〔佘志东〕

超级访谈:对话张雪峰 -〔张雪峰〕

大型Android系统重构实战 -〔黄俊彬〕

超级访谈:对话道哥 -〔吴翰清(道哥)〕

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