2

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

0

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

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'; }
-1

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

1 Comment

This should have been a comment not an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.