PHP get_mangled_object_vars() Function
Last Updated :
28 Feb, 2023
The get_mangled_object_vars() function is an inbuilt function in PHP which is used to return an array of mangled object properties. This function returns an array whose elements are the properties of an object. The keys are the member variable.
Syntax:
array get_mangled_object_vars(object $object)
Parameters: This function accepts one parameter that is described below:
- $object: This parameter specifies an object instance.
Return Value: It returns an array containing all properties, regardless of visibility, of an object.
Example 1: This example demonstrates the get_mangled_object_vars() function.
PHP
<?php
class Articles {
public $public = 1;
protected $protected = 2;
private $private = 3;
}
class GeeksforGeeks extends Articles {
private $private = 4;
}
$object = new GeeksforGeeks ;
$object ->dynamic = 5 ;
$object ->{ '6' } = 5 ;
var_dump(get_mangled_object_vars( $object ));
?>
|
Output:
array(6) {
["public"]=> int(1)
["*protected"]=> int(2)
["Articlesprivate"]=> int(3)
["GeeksforGeeksprivate"]=> int(4)
["dynamic"]=> int(5)
[6]=> int(5)
}
Example 2: This is another example that demonstrates the get_mangled_function() method.
PHP
<?php
class AO extends ArrayObject {
private $private = 1;
}
$arrayObject = new AO([ 'x' => 'y' ]);
$arrayObject ->dynamic = 2;
var_dump(get_mangled_object_vars( $arrayObject ));
?>
|
Output:
array(2) {
["AOprivate"]=> int(1)
["dynamic"]=> int(2)
}
Reference: https://www.php.net/manual/en/function.get-mangled-object-vars.php
Share your thoughts in the comments
Please Login to comment...