There is such a problem: there is a class, and in it methods. But when I try to call these methods, php gives an error that there are no such methods. Although IDE, for example, sees everything.
Here is the class:
<?php class Config { private static $config = null; private $host = 'localhost'; private $userName = 'root'; private $password = ''; private $database = 'keep_lab'; private $lcTimeNames = 'ru_RU'; private $encoding = 'utf8'; public static function getConfig() { if (self::$config === null) { self::$config = new self; } return self::$config; } }
The method is called in another class.
Classes are separated by different files and are in the same directory.
class sources
Here is the method call:
<?php include_once 'Config.php'; class DataBase{ // лишнее вырезано public static function getDB() { if (self::$db === null) { self::$db = new self(Config::getConfig()); } return self::$db; } } // .... $db = DataBase::getDB();
Error text:
Fatal error: Call to undefined method Config::getConfig() in D:\Sergei\Programming\Web-programming\Keep_Notes\www.notes.lb\lib\DataBase.php on line 21
getConfig()
. It is called without error. Everything else is private properties that should not be accessible from outside (private
). So please give a sample code that reproduces the error and post the PHP error message as it is. Otherwise, without explicitly describing the problem, the question may be confused or closed. - Streletz