Jump to content


This topic is now archived and is closed to further replies.


weirdest Error I've ever seen

Recommended Posts

Hello, I have this script that converts my unixtimestamp into "XXXX Ago" time format.



function timeAgo($tm,$rcs = 0) {
    $cur_tm = time(); $dif = $cur_tm-$tm;
    $pds = array('second','minute','hour','day','week','month','year','decade');
    $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
    for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);

    $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
    if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs);
    return $x;



This is how I use the script on my forum script/site.


$member['last_activity'] is a unix Timestamp.


This works wonderful! but here's the problem! I am trying to make it go 2 levels more.  Like instead of just "2 Minutes ago"  It says:

2 Minutes 20 seconds ago


So then I apply how to do that:




See the number 2? Then all of sudden I get this weird ass error...


Fatal error: Call to undefined function timeAgo() in myscript.php on line 1187


1187 line is:

if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs);



Why would it say undefined function when it's in it's own function?

This is weird as hell I am absolutely stumped, any help would be appreciated.

Share this post

Link to post
Share on other sites

Your function works for me.


I know it works, but it brings the error when I try




Whenever I try to add the ,1 or ,2 or ,3 to show "2minutes xx seconds ago" or whatever, instead of just the "2 minutes ago"


Try that way, and let me know ty

Share this post

Link to post
Share on other sites

Works for me, even with constants up to 5 as the second argument.


Copy and paste your code from HERE back into your actual code and try it again.  Maybe you're namespaced weird or there's some non-english character somehow.  Copying and pasting works for me.



Share this post

Link to post
Share on other sites

Also, this is pretty slick.


Wow, the problem was:


I had to add:


$this->timeAgo($_tm, --$rcs);


Because I guess I was calling it from a different .php file, this is in functions.php, and where I am calling it is in skin_profile.php.


I feel like a fool and sorry for wasting everyones time, lol I guess it just helps me to explain my code more out and I can understand it more? Thanks all for trying.


I am going to mark this Resolved.


Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.