Regarding PHP, what are the differences between:
As you can see from the get_class_vars
and get_object_vars
manual pages, get_class_vars
gets the default values of properties of a class, and get_object_vars
gets the current values of properties of an object.
Furthermore, get_class_vars
takes a string (ie. the name of a class), whereas get_object_vars
takes an object.
class Example
{
public $var = 123;
}
$e = new Example();
$e->var = 456;
var_dump(get_class_vars("Example"));
/*
array(1) {
["var"]=>
int(123)
}
*/
var_dump(get_object_vars($e));
/*
array(1) {
["var"]=>
int(456)
}
*/
get_class_vars()
takes the class_name
get_object_vars()
takes an $object variable
They both function similarly:
get_class_vars()
will expose default public variables (or private/protected if called within the class)
get_object_vars()
will expose the current public variables (or private/protected if called within the class object)
Neither will expose methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With