What are the potential drawbacks of using echo statements within a PHP class or function?

Using echo statements within a PHP class or function can make the code less modular and harder to maintain. It can also mix presentation logic with business logic, violating the separation of concerns principle. To solve this issue, it's recommended to use a return statement to return data from the function or class method, and then handle the output in a separate presentation layer.

class Example {
    public function getData() {
        // Process data
        return $data;
    }
}

$example = new Example();
$data = $example->getData();
echo $data;