deeiip
deeiip

Reputation: 3379

error with ob_start() using user defined function inside

function d() {
            return "from d output\n";

        }
        ob_start();
        //var_dump("any thing\n");
        d();
        $a= ob_get_clean();
        echo "$a";

i'm starting doing things in php. I've used this code but in this case no output is being printed to the browser. But whenever I'm using code likevar_dump("anything\n"); within the two ob_ block I'm getting output. My question is what is the difference between the output of var_dump() and my handwritten function d() in this case?

Upvotes: 0

Views: 134

Answers (1)

Álvaro González
Álvaro González

Reputation: 146380

Change this:

d();

... into this:

echo d();

Invoking a function does not automatically print its return value. Or, if you want to mimic var_dump()'s behaviour:

function d() {
    echo "from d output\n";
}

Upvotes: 1

Related Questions