0

I have a class Config. Whenever 'localhost' is in $_SERVER['HTTP_HOST'], I want the $db_host to be 'localhost'. By default it should be 'defaulthost';

class Config {

    public static $db_username = 'username';
    public static $db_password = 'password';
    public static $db_database = 'database';

    public function __construct() {
        $host = 'defaulthost';
    if(stristr($_SERVER['HTTP_HOST'],'localhost')){
        $host = 'localhost';
    };
        self::$db_host = $host;
    }
 }

This code is giving me an error

1
  • so... public static $db_host; should fix that up... Commented Feb 6, 2014 at 23:28

2 Answers 2

2

You just need to declare property $db_host.

class Config {
    public static $db_username = 'username';
    public static $db_password = 'password';
    public static $db_database = 'database';
    public static $db_host = 'defaulthost';

    public function __construct() {
        if (stristr($_SERVER['HTTP_HOST'], 'localhost')){
            self::$db_host = 'localhost';
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You should initialize db_host in same way like you did with db_database ;-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.