Re: Static method to get class variable (PHP4)



Sjoerd wrote:
Markus Ernst wrote:
In order to make static class variables accessible in a clean way I try
to write a method in the base class, as shown in this example:

You probably mean private/protected instead of static.

<?php
class childclass
{
var $types = array('text', 'password', 'hidden');
function get_types() {
return $types;
}
}

print_r(childclass::get_types());
?>

The variable $types does not exist until an instance of this class is
made:

$foo = new childclass();
$foo->get_types();


anyway, the code from above will still not work until you change
function to return:

function get_types() {
return $this -> types;
}
.