I am not sure if this is possible, however, can we build a method that returns or echo the result based on calling the method directly or used in assignment
function foo()
{
return "bar";
}
$abc = foo();
// $abc will have the value "bar"
But if foo() is called directly, it should echo "bar"
foo();
// should echo / print "bar"
adding echo before foo() solves the problem, but how could this be achieved without using echo. Probably adding some line of code to the function foo()
eval())$x = function() { return call_user_func(chr(102).str_repeat('o', 2)); }; eval('echo $x();');