0

I have this function


function theme_status_time_link($status, $is_link = true) {
    $time = strtotime($status->created_at);
    if ($time > 0) {
        if (twitter_date('dmy') == twitter_date('dmy', $time) && !setting_fetch('timestamp')) {
            $out = format_interval(time() - $time, 1). ' ago';
        } else {
            $out = twitter_date('H:i', $time);
        }
    } else {
        $out = $status->created_at;
    }
    if ($is_link)
        $out = "<a href='status/{$status->id}' class='time'>$out</a>";
    return $out;
}

and this

function twitter_is_reply($status) {
    $html = " <b><a href='user/{$status->from->screen_name}'>{$status->from->screen_name}</a></b><br /> $actions $link<br />{$text} <small>$source</small>";
}

I need to pass the variable $out from the first function to the second function, precisely to the $html variable in the second function. However, everything I try either gives me errors and outputs nothing. Without using globals because it appears multiple times in my script. Thanks.

2
  • Why do not you use reference: theme_status_time_link($status, $is_link = true, &$buffer){ ... } function twitter_is_reply($status, &$buffer) { .. } Is it what you think? By this you will be able to pass a reference to a variable. Tell me if this is your point. The second thing is you can call the second function in the first function, immediately before return. Commented Jul 12, 2011 at 21:37
  • 2
    can't you extends twitter_is_reply with a second parameter function twitter_is_reply($status, $out) {...} ? If else - provide more info how twitter_is_reply should be called... Commented Jul 12, 2011 at 21:39

2 Answers 2

2

If you want to use functions send it as an argument:

function twitter_is_reply($status, $html) {
    $html .= " <b><a href='user/{$status->from->screen_name}'>{$status->from->screen_name}</a></b><br /> $actions $link<br />{$text} <small>$source</small>";

    return $html;
}

Usage:

$out = theme_status_time_link();

echo twitter_is_reply('helloworld', $out);
Sign up to request clarification or add additional context in comments.

Comments

0

Now you start to understand why OO is so good.
Create one class, make the $out a member of it and the two functions, make them methods of that class.

1 Comment

If I understood any of the above, I wouldn't be asking this question.

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.