3raser Posted October 16, 2012 Share Posted October 16, 2012 The below function worked just fine when it was in a non-static format. However, whenever I put it into static format and called the function this error was generated: Fatal error: Access to undeclared static property: server::$class in C:\wamp\www\rsplaypages\structure\server.php on line 11 Any idea whay self::$class isn't working? public static function loadClass($class){ if(self::$class == null){ if(file_exists($class.'.php')){ include($class.'.php'); self::$class = new $class(); }else{ self::throwError('class '. $class.' does not exist'); } }else{ self::throwError($class. 'already loaded.'); } } Thanks. Link to comment https://forums.phpfreaks.com/topic/269547-access-to-undeclared-static-property/ Share on other sites More sharing options...
KevinM1 Posted October 16, 2012 Share Posted October 16, 2012 Can you show the rest of your class? Link to comment https://forums.phpfreaks.com/topic/269547-access-to-undeclared-static-property/#findComment-1385626 Share on other sites More sharing options...
3raser Posted October 16, 2012 Author Share Posted October 16, 2012 Sorry about that <?php class server{ protected $database; function __construct(){ self::$database = loadClass($database); } public static function loadClass($class){ if(self::$class == null){ if(file_exists($class.'.php')){ include($class.'.php'); self::$class = new $class(); }else{ self::throwError('class '. $class.' does not exist'); } }else{ self::throwError($class. 'already loaded.'); } } public static function dropClass($class){ self::$class = null; } public static function runMethod($class, $method, array $params = array()){ if(self::isLoaded($class)){ if(count($params) != 0){ $par = ''; $i = 1; foreach($params as $key => $value){ $par .= ($i == count($params)) ? $method : $method.','; $i++; } } self::$class->$method(($par != null) ? $par : null); }else{ self::throwError($class .' is not loaded.'); } } protected static function isLoaded($class){ return (self::$class == null) ? false : true; } protected static function throwError($error){ die('<link rel="stylesheet" href="css/error.css" media="all" /><div class="error"><img src="img/error.png" width="45" height="40"><br/><h4>Error!</h4><div class="err_msg">'. $error .'</div></div>'); } } ?> Link to comment https://forums.phpfreaks.com/topic/269547-access-to-undeclared-static-property/#findComment-1385631 Share on other sites More sharing options...
DarkerAngel Posted October 16, 2012 Share Posted October 16, 2012 Is this another autoload class? Link to comment https://forums.phpfreaks.com/topic/269547-access-to-undeclared-static-property/#findComment-1385633 Share on other sites More sharing options...
3raser Posted October 16, 2012 Author Share Posted October 16, 2012 Is this another autoload class? Yes, but my version of it. Link to comment https://forums.phpfreaks.com/topic/269547-access-to-undeclared-static-property/#findComment-1385637 Share on other sites More sharing options...
kicken Posted October 16, 2012 Share Posted October 16, 2012 You need to declare your class property. Private static $class; Link to comment https://forums.phpfreaks.com/topic/269547-access-to-undeclared-static-property/#findComment-1385645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.