I have got this function that returns a constant..Here is my class and function:
class Backlinks extends GoogleSearch {
const ROBOTS_NOINDEX_NOFOLLOW = 606;
function robotsNoIndexNoFollow(){
$crawler = new Connection();
$curl = $crawler -> setUrl($this->url) ->getDocument();
if ($curl){
$html = new simple_html_dom($curl);
$robots = $html -> find("meta[name=robots]", 0);
$html -> clear();
unset ($crawler);
if ($robots){
$content = $robots -> getAttribute("content");
$content = strtolower($content);
if (substr_count($content, "noindex")){
return ROBOTS_NOINDEX_NOFOLLOW;
}
if (substr_count($content, "nofollow")){
return ROBOTS_NOINDEX_NOFOLLOW;
}
}
else{
return false;
}
}
}
The problem above is in the ROBOTS_NOINDEX_NOFOLLOW contatnt.
The constant goes into another function as an error parameter to be updated in the database.
public function setStatus($error){
$status = $error;
if (!$error){
$status = 200;
}
// only update the pages which weren't already scanned (for historic purposes).
$query = "UPDATE task_pages tp
SET scan_status = $status
WHERE page_id = $this->pageID AND scan_status = 0";
mysql_query($query) or die(mysql_error());
}
I get two errors:
Notice: Use of undefined constant ROBOTS_NOINDEX_NOFOLLOW – assumed
‘ROBOTS_NOINDEX_NOFOLLOW’ in C:\Program Files
(x86)\Zend\Apache2\htdocs\backlinks\cron\Backlinks.php on line 78
Unknown column ‘ROBOTS_NOINDEX_NOFOLLOW’ in ‘field list’
One is the problem with the constant not being defined..which I dont understand why.
The second problem is with the sql..which interprets the constant as a column?!?
Why and how to correct that?
You need to use ‘self’ to reference the constant:
return self::ROBOTS_NOINDEX_NOFOLLOW
Otherwise, PHP would try to find the constant in the global scope even though in your case this is a class constant.