Problem with function output at specified location

Hello! I have a class, and there is a function in it, in which the text (displayed by the echo operator), I deduce the function from the class on the page, but the text is not displayed where it should be, but at the very top of the page, and with the help of return it does not display anything at all . What to do? The function itself is called like this

$class = new main;
$page = $class->page_profile();

And $page is displayed by the echo operator, but for some reason everything outputs wrong. Why?


Answer 1, authority 100%

function page_profile () {
  ob_start(); //  
  /* code, echo, print... NOT return*/
  $str = ob_get_contents(); //  
  ob_end_clean(); //  
  return $str; //  )
  }

Answer 2, authority 100%

return

You are generally fine, you have returneverywhere, no matter what you check, so return.

return only at the very end of the function!

More cooler

while($messages = mysql_fetch_array($tmp));
    //    while,     ?   , ,   ,      -?  .
}
else {
    //   
    return " ";
}

And if you immediately give it to your forehead, then the error is that you have RETURNeverywhere and there is no sense from your function.

7 line

<title><?php return $myrow['login']; ?></title>

At this point, the interpreter comes and returns what it should, namely

<html>
<head>
<title>

What you want is returned, write the code correctly and you will be happy.

I have everything.

PPS The code is shitcode, sorry, of course, but is it the first time you wrote a function or did you honestly steal it from somewhere?

function funct() {
    $number = 1234567;
    return $number; //  1234567 RETURN   ,         ,     .
}

Answer 3

Well, as far as I understand (turn on telepathy, since those three lines are not enough to make a picture of the code) $page = $class->page_profile();– by doing this you and output that text, because there is echo(“there is a class in it, and there is a function in it in which the text (displayed by the echo operator)”), and you expect the output to be lower when you do: echo $page;if I’m right, then you have two solutions or write $class->page_profile();(or even main::page_profile(), well, we are already looking at the class code itself) at the place where echo $page;or change the implementation of the page_profile()method, making it not echo, a return.