简体   繁体   中英

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 like var_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?

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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM