English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP tutorial

Advanced PHP tutorial

PHP & MySQL

PHP reference manual

PHP get_class_vars() function usage and example

PHP Class/Object function reference manual

The get_class_vars() function returns an array composed of the default properties of the class

Syntax

get_class_vars( \$class_name );

Definition and usage

This function retrieves the default properties of the given class. Returns an associative array of the default public properties of the class.

Parameter

Serial numberParameters and descriptions
1

class_name(Required)

Class name.

Return value

It returns an associative array of default public properties of the class. The form of the array elements is varname => value. If an error occurs, FALSE is returned.

Online example

The following is the usage of this function, returning an array composed of default properties of the class

<?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";
   }
?>
Test and see‹/›

It will produce the following result-

var1 :
var2 : xyz
var3 : 100

  PHP Class/Object function reference manual