I can't understand as to why this variable isn't working inside this class, the following error shows up:
Parse error: syntax error, unexpected '$_SERVER' (T_VARIABLE)
I read that it should be used the following way: $this->url()
but it doesn't seem like PHP allows variables nor superglobals inside classes, is there a way around this?
class socialCounter
{
public $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
public function getPlus()
{
$html = file_get_contents( "https://plusone.google.com/_/+1/fastbutton?url=".urlencode($this->url());
libxml_use_internal_errors(true);
$doc = new DOMDocument(); $doc->loadHTML($html);
$counter=$doc->getElementById('aggregateCount');
return $counter->nodeValue;
}
public function getTweets(){
$json = file_get_contents( "http://urls.api.twitter.com/1/urls/count.json?url=".$this->url() );
$ajsn = json_decode($json, true);
$cont = $ajsn['count'];
return $cont;
}
}