Question

I've looked at debug_backtrace but so far it doesn't do what I need it to do.

I need to know whether the function I'm calling was 'called' or 'echo-ed'. Like this:

function hello() {
    //blah blah
}

echo hello(); //echo-ed
hello(); //'called'

But the function would do different things if it was 'called' over 'echo-ed'.

How would I do that?

Was it helpful?

Solution

I am pretty sure that this is impossible. The reason this cannot work is that "echo" or any other operator, function or variable assignment uses the return value of the function you've called. So if you've got the following:

echo function1();

What happens is that function1 gets executed, and the return value is passed to echo. Therefor, function1 cannot possibly know that its return value is going to be "echo-ed", because by the time that happens, function1() has already been called and finished executing.

OTHER TIPS

There is no efficient way to deal it

Update: There is no way to deal it :)

two examples to help you understand.

function hello(){
  return "Hello!";
}
echo hello(); // prints Hello!


function hello(){
  echo "Hello!";
}
hello(); // prints Hello!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top