views:

82

answers:

2

Hello, 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

A: 

Is the code meant to use time_since() when the other method you have listed is time_stamp()?

This should have been a comment not an answer.
HoLyVieR
+4  A: 

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().

m1tk4
Sorry, I time_stamp was a typo. So, I've got it like this now, to no avail. (These are just examples instead of typing out all the code) 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']).'">'.self::time_since($d['dt']).'</div>'; } public static function time_stamp($time){ //do stuff with the received string return 'new time string'; }
Ryan