When debugging some php scripts it would be very handy if I had a shortcut that would insert a piece of text like an echo with the current linenumber and filename.
echo “Hello at filename.php at linenumber”;
Even auto inserting some text like a comment with a static echo would be sweet.
/* DEBUG */
echo “in here”;
Is this possible in php?
The variables you are looking for are called
__LINE__. A simple mapping in vim could give you the desired result:
:map <C-L> oecho __FILE__ . ':' . __LINE__ . " - ";<C-O>h
o– Start inserting below current line
echo __FILE__ . ':' . __LINE__ . " - ";– Write this string
<C-O>– Perform a single command in command mode
h– Go one character to the left, which should position your cursor at the end of the string so you can insert your debug statement.
While this should be ok for quick fixes, you might consider using a logger for debug messages (maybe Pear::Log?)