get_defined_vars() inside a class
How do i get all defined global variables inside a class function?
When I call the get_defined_vars()
function inside a class method开发者_如何学C I only get an empty object.
via => Define variables outside the PHP class
class Foo {
function bar(){
var_dump($GLOBALS);
}
}
Foo::bar();
outputs :
array(8) {
["GLOBALS"]=>
array(8) {
["GLOBALS"]=>
*RECURSION*
["_POST"]=>
array(0) {
}
/*snip*/
Use get_class_vars(__CLASS__)
if you want the predefined variables & values (those values defined and set as default before an object initialized).
Use get_object_vars($this)
if you want all the variables (instance variables) including those which are created temporarily for a particular object while executing any method of the class.
I know these are not really the things you need. Its $GLOBALS
that you need answered yourself. But I just gave these methods for your reference so that may be useful in the future.
Maybe you can try get_class_vars()
?
精彩评论