I’m trying to debug a class and using print_r and echo to view the variables as the script progresses.
However for some reason I can’t seem to get any output from within the function, i’ve declared the function public but can’t get any output using print, echo or print_r.
I’m misunderstanding something fundamental here – can anyone help please.
here’s some extract from my code:
this call is from within a public function within the class:
$xml_data = $this->convert_to_xml($rs);
The method looks like this:
public function convert_to_xml($rs) {
echo "test variable:";
print_r($rs);
}
The print_r was purely to test the values were being passed, but I don’t get any output at all
If you want to return the value to assign it to
$xml_data, you must actually return it instead of echoing it.echosend the value directly to the output stream, whilereturnreturns the value from the function, so that it can be assigned to a variable or be used in other expressions: