In PHP, if I have a class with static member variables, for example:
class Foo
{
public static $a = 0;
public static $b = 1;
}
... and I have a string variable containing the class name:
$foo = 'Foo';
... how do I iterate over the elements of a static class element Foousing a variable $foo?
Sort of:
// Does not work
foreach ($foo AS $field => &$value) {
// Desired:
// Iteration 1: $field = 'a', $value = 0
// Iteration 2: $field = 'b', $value = 1
}
As noted, the code snippet above does not work.
Is it possible? If so, what is the syntax?
Thank.
source
share