<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Right Up Top &#187; php</title>
	<atom:link href="http://www.rightuptop.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rightuptop.com</link>
	<description>Incredible. I'm having an incredible year.</description>
	<lastBuildDate>Tue, 22 Dec 2009 23:45:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>The Greatest PHP Debugging Function of All Time</title>
		<link>http://www.rightuptop.com/techie/the-greatest-php-debugging-function-of-all-time/</link>
		<comments>http://www.rightuptop.com/techie/the-greatest-php-debugging-function-of-all-time/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 20:27:22 +0000</pubDate>
		<dc:creator>jake</dc:creator>
				<category><![CDATA[Techie]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.rightuptop.com/?p=756</guid>
		<description><![CDATA[I normally try to keep the tech stuff to a minimum on the blog, but this function is in high demand from anyone who&#8217;s ever had it and then worked on another codebase without it.  Simple, but mind-blowingly useful. Without further ado, I present, YO. NOTE: This is a re-write of some code I wrote [...]


Related posts:<ol><li><a href='http://www.rightuptop.com/techie/crows-you/' rel='bookmark' title='Permanent Link: Crows &gt; You'>Crows &gt; You</a></li>
<li><a href='http://www.rightuptop.com/music/top-20-songs-of-the-second-half-of-2005/' rel='bookmark' title='Permanent Link: Top 20 Songs of the Second Half of 2005'>Top 20 Songs of the Second Half of 2005</a></li>
<li><a href='http://www.rightuptop.com/music/top-20-songs-of-2005-so-far/' rel='bookmark' title='Permanent Link: Top 20 Songs of 2005 So Far'>Top 20 Songs of 2005 So Far</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I normally try to keep the tech stuff to a minimum on the blog, but this function is in high demand from anyone who&#8217;s ever had it and then worked on another codebase without it.  Simple, but mind-blowingly useful. Without further ado, I present, <strong>YO</strong>.  </p>
<p>NOTE: This is a re-write of some code I wrote at Yahoo!, so I wanted to give credit to the two folks who had a hand in the debugging system we built there, from which this is derived: Chris and Sara.</p>
<p>You&#8217;re welcome, America.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * The greatest debugging class in history. Here's why:
 * 
 *  - outputs to both the error log and optionally the screen.
 *  - formats output nicely so you can see your debugging output
 *  - shows you where the yo() call is IN THE OUTPUT so if you
 *    leave a yo() in someplace, you can track it down easy-peasy.
 *  - accepts multiple args just like var_dump
 *  - feel free to use the sub functions too (like var_dump_str)
 *   
 * @author Jacob Rosenberg &lt;themasterof@rightuptop.com&gt;
 * @author Sara Golemon
 * @author Chris Draycott
 *
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Yo <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">/* {{{ */</span>
    <span style="color: #009933; font-style: italic;">/**
     * getCallerLine
     *
     * gets the calling line of the function it was called from,
     * i.e., this function's grandparent.
     *
     * @returns string Name of calling function
     */</span>
    static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCallerLine<span style="color: #009900;">&#40;</span><span style="color: #000088;">$levels</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$bt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">/* }}} */</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">/* {{{ */</span>
    <span style="color: #009933; font-style: italic;">/**
     * getCaller
     *
     * gets the calling function of the function it was called from,
     * i.e., this function's grandparent.
     *
     * @returns string Name of calling function
     */</span>
    static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCaller<span style="color: #009900;">&#40;</span><span style="color: #000088;">$levels</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$bt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$caller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'class'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$caller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$levels</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'class'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;::&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$caller</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$caller</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'main'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$caller</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">/* {{{ */</span>
    <span style="color: #009933; font-style: italic;">/**
     * var_dump_str
     *
     * var_dump, but with returned output.
     * OB capture is gross, but print_r($x,1) sucks compared to var_dump.
     *
     * @param mixed PHP Variable to be var_dump'd
     * @returns string var_dump representation of that variable
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> var_dump_str<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">/* }}} */</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * isInternal
     *
     * determines if a user is an internal user.
     *
     * @return bool true if the user is internal and should see debug output
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> isInternal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// feel free to add some code here that</span>
        <span style="color: #666666; font-style: italic;">// turns on debug output for only a subset of users.</span>
        <span style="color: #666666; font-style: italic;">//</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* }}} */</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* {{{ */</span>
    <span style="color: #009933; font-style: italic;">/**
     * yo - figure it out yourself, dummy
     *
     * @param mixed Variable(s) to be dumped (var args)
     * ...
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> do_yo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$internal</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">isInternal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$caller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getCaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$internal</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pre&gt;&lt;h1&gt;YO!!: <span style="color: #006699; font-weight: bold;">$caller</span>&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span>  
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;YO!!:: <span style="color: #006699; font-weight: bold;">$caller</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'bool(false)'</span> <span style="color: #339933;">:</span> Yo<span style="color: #339933;">::</span><span style="color: #004000;">var_dump_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$internal</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$internal</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/pre&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">/* }}} */</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* {{{ */</span>
    <span style="color: #009933; font-style: italic;">/**
     * yo_bt - figure it out yourself, dummy
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> do_yo_bt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$internal</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">isInternal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$caller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getCaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$internal</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pre&gt;&lt;h1&gt;YO bt!!: <span style="color: #006699; font-weight: bold;">$caller</span>&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;YO bt!!:: <span style="color: #006699; font-weight: bold;">$caller</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$bt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$bt</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$internal</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$internal</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/pre&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">/* }}} */</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* }}} */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// shortcuts! ------</span>
<span style="color: #000000; font-weight: bold;">function</span> yo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> Yo<span style="color: #339933;">::</span><span style="color: #004000;">do_yo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> yo_bt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> Yo<span style="color: #339933;">::</span><span style="color: #004000;">do_yo_bt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://www.rightuptop.com/techie/crows-you/' rel='bookmark' title='Permanent Link: Crows &gt; You'>Crows &gt; You</a></li>
<li><a href='http://www.rightuptop.com/music/top-20-songs-of-the-second-half-of-2005/' rel='bookmark' title='Permanent Link: Top 20 Songs of the Second Half of 2005'>Top 20 Songs of the Second Half of 2005</a></li>
<li><a href='http://www.rightuptop.com/music/top-20-songs-of-2005-so-far/' rel='bookmark' title='Permanent Link: Top 20 Songs of 2005 So Far'>Top 20 Songs of 2005 So Far</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.rightuptop.com/techie/the-greatest-php-debugging-function-of-all-time/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
