Welcome Guest, Not a member yet? Register   Sign In
Understanding print_r()
#1

[eluser]tim042829[/eluser]
I've written a little debug stub in vim for PHP variables.
From the variable name, it expands to the following:
Code:
echo "<pre>foo: " . print_r($foo) . "</pre>"; ## DEBUG GLOBAL
Real world example where I am inspecting index.php
Code:
$controller = BASEPATH.'codeigniter/CodeIgniter'.EXT;
echo "<pre>controller: " . print_r($controller) . "</pre>"; ## DEBUG GLOBAL
And the output is
Quote:/home/http/php/ci/system/codeigniter/CodeIgniter.php
controller: 1
Note that controller: 1 is on a second line and tends to be a little
confusing. The output that I am really looking for would be
controller: /home/http/php/ci/system/codeigniter/CodeIgniter.php
OR considering that I will be dealing with complex data structures:
Quote:controller: 1
/home/http/php/ci/system/codeigniter/CodeIgniter.php

How can I make that happen?
thanks
tim
#2

[eluser]WanWizard[/eluser]
Check the PHP manual for print_r(). You'll notice that it prints (echo's) the parameter, and returns true.
#3

[eluser]tim042829[/eluser]
[quote author="WanWizard" date="1289530227"]Check the PHP manual for print_r(). You'll notice that it prints (echo's) the parameter, and returns true.[/quote]
Are you referring to http://www.php.net/manual - link contained in the PHP man page?
If so, I have yet to have found documentation for print_r() at that site.
(but have found all kinds of other interesting and useful functions)

If not, could you point me directly to the documentation?
That would give me some more clues as to how find my way around.
thanks
tim
#4

[eluser]WanWizard[/eluser]
Google "print_r". The first link returned is http://php.net/manual/en/function.print-r.php. Doesn't look to difficult.
#5

[eluser]tim042829[/eluser]
Never mind. I found the documentation under Function Index.
As http://www.php.net/manual/en/indexes.php => http://www.php.net/manual/en/function.print-r.php

BTW: The expansion that works a little better for readability is
Code:
echo "<hr>foo: " ; print_r($foo); ## DEBUG GLOBAL
The vim code :coolsmile: for you vim users is
Code:
function! PHPGlobalDebug()
    let wrd=expand("<cWORD>")
    let cmd = "norm! ^dwaecho \"<hr>" . wrd . ": \" ; " . "print_r($" . wrd ."); ## DEBUG GLOBAL"
     exe cmd
endfunction
and the keymapping I use is
Code:
inoremap <C-d><C-g>  <Esc>:call PHPGlobalDebug()<CR>A
(Obfuscated is a calling function with a filetype switch)
BTW: How did I get to be Grad Student? Heck, I'm still in first grade.




Theme © iAndrew 2016 - Forum software by © MyBB