Created
August 21, 2014 14:17
-
-
Save IQAndreas/ccaebe6d660a7248ca9e to your computer and use it in GitHub Desktop.
Unable to create a PHP function with the same name as a static function. Results in the error message listed below. See: http://stackoverflow.com/q/25428887/617937
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre><?php | |
class Module | |
{ | |
// ---- Static methods ---- | |
private static $config = array(); | |
public static function get_config($module_name, $field) | |
{ | |
if (!isset(Module::$config[$module_name])) | |
{ return null; } | |
else if (!isset(Module::$config[$module_name][$field])) | |
{ return null; } | |
else | |
{ return Module::$config[$module_name][$field]; } | |
} | |
public static function set_config($module_name, $field, $value) | |
{ | |
if (!isset(Module::$config[$module_name])) | |
{ Module::$config[$module_name] = array(); } | |
Module::$config[$module_name][$field] = $value; | |
} | |
// ---- Instance methods ---- | |
private $name; | |
public function __construct($name) | |
{ | |
$this->name = $name; | |
} | |
// Fatal error: Cannot redeclare Module::get_config() in [path]/static-redeclare.php on line 32 | |
public function get_config($field) | |
{ | |
return Module::get_config($this->name, $field); | |
} | |
public function set_config($field, $value) | |
{ | |
Module::set_config($this->name, $field, $value); | |
} | |
} | |
print("------------------------\n"); | |
$m1 = new Module("module1"); | |
$m1->set_config('var1', "Foo"); | |
$m1->set_config('var2', "Bar"); | |
print($m1->get_config('var1')."\n"); | |
print("------------------------\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment