CodeIgniter Forums

Full Version: is this a normal behavior? (echo var_dump of CI Super Object)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jozeunico[/eluser]
Try this function please:

Code:
function Foo()
    {
        $message_one = 'Message ONE';
        $message_two = 'Message TWO';
        $CI = &get;_instance();
        echo "<br/>message_one:".$message_one;
        echo "<br/>message_two:".$message_two;
        echo "<br/>Var Dump of CI:<br>:".var_dump($CI);
    }

The output it will be something like:

message_one:Message ONE
message_two:Message TWOobject(Welcome)#9 (10) { ["_ci_scaffolding"]=> bool(false) ["_ci_scaff_table"]=> bool(false) ["config"]=> &object;(CI_Config)#3 (2) { ["config"]=> &array;(34) { ["base_url"]=> string(34) "http://localhost/pruebas/Mylibrary" ["index_page"]=> string(9) "index.php" ....THIS STUFF CONTINUES AND AFTER IT COMES:Var Dump of CI:

Just in case that you didn't notice, the var_dump function's result and the message "Var Dump of CI" are in reverse order at the output in the browser.In fact I was expecting something like:


message_one:Message ONE
message_two:Message TWO
Var Dump of CI:object(Welcome)#9 (10) { ["_ci_scaffolding"]=> bool(false) ["_ci_scaff_table"]=> bool(false) ["config"]=> &object;(CI_Config)#3 (2) { ["config"]=> &array;(34) { ["base_url"]=> string(34) "http://localhost/pruebas/Mylibrary" ["index_page"]=> string(9) "index.php" ....AND SO ON...


I know this is not a "big deal" but it seems really weird to me. So if someone can tell me if this is a bug in CI or even of var_dump function or maybe a normal behavior or any reason about this I'll be really grateful.

I gave a quick look to the source code of the html generated and I notice something weird (Ctrl-U with FireFox 2.x/3.x) probably with quotes,the source code it turns red just from :

["&lt;![CDATA["]=>
string(12) "&lt;![CDATA["
}

'til the end, but I have no idea about this behavior.

El Forum

[eluser]Mark Croxton[/eluser]
Interesting.

What happens if you wrap your code in ob_start() and ob_flush() ?

El Forum

[eluser]rogierb[/eluser]
This is normal behaviour for var_dump(). Is outputs directly to the browser. During the processesing of echo var_dump get triggered and it outputs to the browser before the message get processed.

El Forum

[eluser]Phil Sturgeon[/eluser]
You should be running var_dump by itself. This is expected, as PHP will run var_dump looking for a returned string to concat on the end of your echo string. When the function is run, it will directly echo the contents of CI super-global, and then continue on with processing the string.

Code:
$message_one = 'Message ONE';
        $message_two = 'Message TWO';
        $CI = &get;_instance();
        echo "<br/>message_one:".$message_one;
        echo "<br/>message_two:".$message_two;
        echo "<br/>Var Dump of CI:<br>:";
        var_dump($CI);

Nothing to do with CI, just plain old PHP precedence. :-)

El Forum

[eluser]Phil Sturgeon[/eluser]
[quote author="rogierb" date="1259266351"]This is normal behaviour for var_dump(). Is outputs directly to the browser. During the processesing of echo var_dump get triggered and it outputs to the browser before the message get processed.[/quote]

Sneaky bugger, just beat me to it.

El Forum

[eluser]jozeunico[/eluser]
Ahhh, thank you, yeap I try with var_dump of the $message_one and it's the same, well I'm sorry for wasting your time and thank you again.