<?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>blarg.co.uk</title>
	<atom:link href="http://www.blarg.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blarg.co.uk</link>
	<description>bringing blarg to the masses!</description>
	<lastBuildDate>Fri, 23 Sep 2011 13:34:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP Fatal error: Can&#8217;t use method return value in write context</title>
		<link>http://www.blarg.co.uk/2010/11/php-fatal-error-cant-use-method-return-value-in-write-context/</link>
		<comments>http://www.blarg.co.uk/2010/11/php-fatal-error-cant-use-method-return-value-in-write-context/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 23:22:45 +0000</pubDate>
		<dc:creator>wrakky</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.blarg.co.uk/?p=144</guid>
		<description><![CDATA[I came across the following error recently when trying to evaluate in PHP whether a value was empty: Fatal error: Can't use method return value in write context It turns out that the PHP empty function cannot accept the return value from another function so you have to first define the variable before passing it [...]]]></description>
			<content:encoded><![CDATA[<p>I came across the following error recently when trying to evaluate in PHP whether a value was empty:</p>
<p><code>Fatal error: Can't use method return value in write context</code></p>
<p>It turns out that the PHP <a title="view the documentation for the PHP empty function" href="http://php.net/manual/en/function.empty.php" target="_blank">empty function</a> cannot accept the return value from another function so you have to first define the variable before passing it to the empty() function.</p>
<pre class="brush: php; title: ; notranslate">
// will generate a fatal error
empty(nl2br($string));
empty($obj-&gt;getSomeValue());

// will work
$val = nl2br($string);
$val = $obj-&gt;getSomeValue();
empty($val);
</pre>
<p>Alternatively, you can use the following function instead:</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Determines whether a variable is considered to be empty,
 * additionally accepts returned values from functions
 *
 * @param mixed	$val	The value to evaluate
 * @return boolean
 */
function empty_return($val) {
	return empty($val);
}

// example
empty_return(nl2br($string));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.blarg.co.uk/2010/11/php-fatal-error-cant-use-method-return-value-in-write-context/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Firebug console wrapper</title>
		<link>http://www.blarg.co.uk/2010/11/firebug-console-wrapper/</link>
		<comments>http://www.blarg.co.uk/2010/11/firebug-console-wrapper/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 00:39:52 +0000</pubDate>
		<dc:creator>wrakky</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.blarg.co.uk/?p=105</guid>
		<description><![CDATA[The Firebug console is extremely useful when trying to debug javascript. However, for users that don&#8217;t have Firebug installed or are using a browser without a built in console, you either have to delete all logging from your scripts before publishing them or create a &#8220;dummy&#8221; console object to prevent errors. A more convenient method [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="visit the Firebug website" href="http://getfirebug.com/" target="_blank">Firebug</a> console is extremely useful when trying to debug javascript. However, for users that don&#8217;t have Firebug installed or are using a browser without a built in console, you either have to delete all logging from your scripts before publishing them or create a &#8220;dummy&#8221; console object to prevent errors.</p>
<p>A more convenient method is to create a wrapper for the console that you can call instead.<span id="more-105"></span></p>
<p>This method creates a function called <code>log</code> which can be called from your javascript and takes the first argument as the console command you want to execute and then any number of extra parameters which are passed to the command.</p>
<pre class="brush: jscript; title: ; notranslate">

log('log', 'test');  // console.log('test');

log('info', 'something', 'else');  // console.info('something', 'else');

log('group', 'A Group');  // console.group('A Group);

log('groupEnd');  // console.groupEnd();
</pre>
<p>All commands in the <a title="view the Firebug Console API" href="http://getfirebug.com/wiki/index.php/Console_API" target="_blank">Firebug Console API</a> commands are supported and they way the wrapper is built means that any new ones added in the future will also be supported.</p>
<p>Additional functionality of the wrapper includes being able to turn off console output completely for when you don&#8217;t want your debugging to be output and a default command which lets you use the console without specifying a method to execute. For example, most of my logging is done using <code>console.log</code> so instead of having to write <code>log('log', 'something')</code> each time, I can just use <code>log('something')</code> and it will know that the first argument is not a valid console command and use the default option instead.</p>
<pre class="brush: jscript; title: ; notranslate">

// log.js

(function(enableLog) {

	/**
	 * The default command, if the first argument is not a valid console command
	 * it will be output as this
	 */
	var defaultCommand = 'log';

	/**
	 * Executes a console command
	 */
	function applyCommand(command, args) {

		/**
		 * if the command is a valid console command
		 */
		if (!!console[command] &amp;&amp; typeof console[command] === 'function') {

			// execute the command
			console[command].apply(this, args);

			// return true
			return true;

		}

		// return false because the command did not exist
		return false;

	}

	// define the function in the global scope
	window.log = function() {

		// if logging is enabled and console exists
		if (enableLog &amp;&amp; !!window.console) {

			// convert arguments to array
			var args = Array.prototype.slice.call(arguments);

			// remove first item in args - this should be the console command
			var command = args.shift();

			// call the command
			if (!applyCommand(command, args)) {

				// add first item back to args as it wasn't the command
				args.unshift(command);

				// call default command
				applyCommand(defaultCommand, args);

			}

		}

	};

})(true); // true to output to console, false to suppress
</pre>
<p>Minified version:</p>
<pre class="brush: jscript; title: ; notranslate">
(function(d){function c(a,b){if(console[a]&amp;&amp;typeof console[a]===&quot;function&quot;){console[a].apply(this,b);return true}return false}window.log=function(){if(d&amp;&amp;window.console){var a=Array.prototype.slice.call(arguments),b=a.shift();if(!c(b,a)){a.unshift(b);c(&quot;log&quot;,a)}}}})(true);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.blarg.co.uk/2010/11/firebug-console-wrapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Collapse FirePHP Responses</title>
		<link>http://www.blarg.co.uk/2010/11/automatically-collape-firephp-responses/</link>
		<comments>http://www.blarg.co.uk/2010/11/automatically-collape-firephp-responses/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 14:07:39 +0000</pubDate>
		<dc:creator>wrakky</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.blarg.co.uk/?p=79</guid>
		<description><![CDATA[FirePHP is a Firefox extension that allows you to log directly to the Firebug console from PHP. This is great for AJAX applications because you can debug your server side scripts without interferring with the responses. Each script that returns a FirePHP log will generate it&#8217;s own group in the Firebug console which is expanded [...]]]></description>
			<content:encoded><![CDATA[<p><a title="visit the FirePHP website" href="http://www.firephp.org/" target="_blank">FirePHP</a> is a Firefox extension that allows you to log directly to the <a title="visit the Firebug website" href="http://getfirebug.com/" target="_blank">Firebug</a> console from PHP. This is great for AJAX applications because you can debug your server side scripts without interferring with the responses.</p>
<p>Each script that returns a FirePHP log will generate it&#8217;s own group in the Firebug console which is expanded by default which means if you are logging a lot of data on the server side (such as database queries) then there will be a lot of data displayed in the console which you may not want to see all the time.</p>
<p>My solution to this was to edit the FirePHP extension so that each script response is collapsed automatically. You can then click a response to expand it if you want to view more details.<span id="more-79"></span></p>
<p>In order to do this you will need to edit the <code>RequestProcessor.js</code> file in the FirePHP install directory which should located inside your <a title="How to find your Firefox profile folder" href="http://kb.mozillazine.org/Profile_folder_-_Firefox" target="_blank">Firefox profile folder</a> at: <code>extensions\FirePHPExtension-Build@firephp.org\chrome\content\firephp\RequestProcessor.js</code></p>
<p>You will need to edit line 411 which reads:</p>
<pre class="brush: jscript; first-line: 411; title: ; notranslate">
    Firebug.Console.openGroup([URL], null, &quot;firephpRequestGroup&quot;, null, true);
</pre>
<p>and change it to:</p>
<pre class="brush: jscript; first-line: 411; title: ; notranslate">
    var row = Firebug.Console.openGroup([URL], null, &quot;firephpRequestGroup&quot;, null, true);
    removeClass(row, &quot;opened&quot;);
</pre>
<p>Once you save these changes you can just restart Firefox and now each FirePHP group will be collapsed by default.</p>
<p>If you would like to be able to toggle on and off automatic collapsing then you can do so by navigating your browser to <code><a class="linkification-ext" title="Linkification: about:config" href="about:config">about:config</a></code> and adding a boolean preference key with the name <code>extensions.firephp.collapse</code>. Then replace line 411 in <code>RequestProcessor.js</code> with:</p>
<pre class="brush: jscript; first-line: 411; title: ; notranslate">
	var row = Firebug.Console.openGroup([URL], null, &quot;firephpRequestGroup&quot;, null, true);

	if (FirePHP.getPref(FirePHP.prefDomain, 'collapse')) {
		removeClass(row, &quot;opened&quot;);
	}
</pre>
<p>If the <code>extensions.firephp.collapse</code> is <code>true</code> the response will be collapsed, if it is <code>false</code> then it will be expanded.</p>
<p>Finally, a word of warning. If a new version of FirePHP is released and you install it, these changes will be overwritten and will need to be applied again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blarg.co.uk/2010/11/automatically-collape-firephp-responses/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alternative DATEDIFF for MySQL</title>
		<link>http://www.blarg.co.uk/2010/10/alternative-datediff-for-mysql/</link>
		<comments>http://www.blarg.co.uk/2010/10/alternative-datediff-for-mysql/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 16:12:34 +0000</pubDate>
		<dc:creator>wrakky</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.blarg.co.uk/?p=52</guid>
		<description><![CDATA[The DATEDIFF() function was added in MySQL version 4.1.1. For earlier versions that do not support this function you can make a work-around for it using the TO_DAYS function: This will give the same effect as DATEDIFF(date1, date2) by converting each date to the number of days since year 0 and subtracting them. Note: According [...]]]></description>
			<content:encoded><![CDATA[<p>The DATEDIFF() function was added in MySQL version 4.1.1. For earlier versions that do not support this function you can make a work-around for it using the TO_DAYS function:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT TO_DAYS(date1) - TO_DAYS(date2);

-- example
SELECT TO_DAYS('2010-01-03') - TO_DAYS('2010-01-01'); -- returns '2'
</pre>
<p>This will give the same effect as <code>DATEDIFF(date1, date2)</code> by converting each date to the number of days since year 0 and subtracting them.</p>
<p><strong>Note:</strong> According the <a href="http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_to-days">MySQL manual</a>, TO_DAYS() is not intended for use with dates that precede the year 1582 because it does not take into account the days that were lost when the Gregorian calendar was introduced so using this method is not advisable for dates earlier than this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blarg.co.uk/2010/10/alternative-datediff-for-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blarg!</title>
		<link>http://www.blarg.co.uk/2010/10/blarg/</link>
		<comments>http://www.blarg.co.uk/2010/10/blarg/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 15:46:40 +0000</pubDate>
		<dc:creator>wrakky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.blarg.co.uk/?p=50</guid>
		<description><![CDATA[blarg.co.uk is back!]]></description>
			<content:encoded><![CDATA[<p>blarg.co.uk is back!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blarg.co.uk/2010/10/blarg/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.blarg.co.uk @ 2012-05-20 08:56:45 -->
