I’m trying to call a function within a string return statement. Both are in the same class. However, I’m obviously not calling it right because it doesn’t work 🙂
private static function doSomething(){
$d['dt'] = //unix time stamp here;
return '<div class="date" title="Commented on '.date('H:i \o\n d M Y',$d['dt']).'">'.time_since($d['dt']).'</div>';
}
function time_since(){
//return 'string';
}
Any help is appreciated! Thanks
First, you are calling time_since() and your function is time_stamp().
Second, in PHP you need to explicitly call it like $this->time_stamp() – it does not resolve it to object scope like C++ does.
Third, you cannot call a regular method from the static function because the object is not instantiated – make time_stamp() static too. If you do this, it needs to be invoked like self::time_stamp().