ive browsed many articles here but I just can't make this work for the life of me.
class Database{
private $host;
function __construct( $vhost = ''){
$this->host = $vhost == '' ? db_host : $vhost;
}
function connect(){
echo "Host: ".$this->host;
}
}
I've omitted some unnecessary code but it's same concept. I get "Fatal error: Using $this when not in object context" when trying to echo. What am I missing here?
You probably call Database::connect() instead of $somevar->connect(). You can't refer to this in static context indeed.
ReplyDelete