<?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>Electricmonk.nl weblog &#187; php</title>
	<atom:link href="http://www.electricmonk.nl/log/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.electricmonk.nl/log</link>
	<description>Ferry Boender&#039;s ramblings</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:23:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Templum v0.4.0 released (Simple PHP templating)</title>
		<link>http://www.electricmonk.nl/log/2009/11/10/templum-v0-4-0-released-simple-php-templating/</link>
		<comments>http://www.electricmonk.nl/log/2009/11/10/templum-v0-4-0-released-simple-php-templating/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 08:51:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[libre software]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2009/11/10/templum-v0-4-0-released-simple-php-templating/</guid>
		<description><![CDATA[I&#039;ve released Templum v0.4.0 Templum is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum is very fast; it approximates native PHP rendering speed for include() statements. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve released <a href="http://templum.electricmonk.nl/Download/">Templum v0.4.0 </a></p>
<p><a href="http://templum.electricmonk.nl">Templum</a> is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum is very fast; it approximates native PHP rendering speed for include() statements.</p>
<p>This release features:</p>
<ul>
<li>Some small bug fixes</li>
<li>Documentation updates</li>
<li>The ability to <a href="http://templum.electricmonk.nl/docs/userguide/userguide.html#_including">include</a> other templates in a template</li>
</ul>
<p>Download instructions <a href="http://templum.electricmonk.nl/Download/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2009/11/10/templum-v0-4-0-released-simple-php-templating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Templum v0.2.0: Simple PHP Templating</title>
		<link>http://www.electricmonk.nl/log/2009/04/26/templum-v020-simple-php-templating/</link>
		<comments>http://www.electricmonk.nl/log/2009/04/26/templum-v020-simple-php-templating/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 19:22:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4357</guid>
		<description><![CDATA[I just released v0.2.0 of Templum, a simple templating engine for PHP. About From the homepage: Templum is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum [...]]]></description>
			<content:encoded><![CDATA[<p>I just released v0.2.0 of <a href="http://templum.electricmonk.nl">Templum</a>, a simple templating engine for PHP.</p>
<h3>About</h3>
<p>From the homepage:</p>
<blockquote><p>
Templum is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum is very fast; it approximates native PHP rendering speed for include() statements.
</p></blockquote>
<h3>Changes</h3>
<p>Changes in this release:</p>
<ul>
<li>PHP 4 support added (patch by Pierre Jochem).</li>
<li>Bugfix (#1): {{$var}} at end-of-line eats newline following it.</li>
<li>Various examples added.</li>
<li>Added the ability to turn off automatic escaping using htmlentities().</li>
<li>Improved the error reporting.</li>
<li>The locale can now be changed after creating a Templum instance.</li>
<li>Userguide updated.</li>
</ul>
<p>This release is backwards compatible with the previous version 0.1.0.</p>
<h3>Install</h3>
<p>You can install Templum v0.2.0 using PEAR:</p>
<pre>
pear install http://templum.electricmonk.nl/releases/templum-0.2.0.tgz
</pre>
<p>If you&#039;ve got a previous version of Templum installed, you must first uninstall that one:</p>
<pre>
pear uninstall channel://__uri/templum-0.1.0
</pre>
<p>There&#039;s also a non-PEAR tar.gz which also contains examples and the API documentation and Userguide:</p>
<p><a href="http://templum.electricmonk.nl/releases/templum-src-0.2.0.tar.gz">templum-src-0.2.0.tar.gz</a>.</p>
<h3>More information</h3>
<ul>
<li><a href="http://templum.electricmonk.nl">Homepage</a></li>
<li><a href="http://templum.electricmonk.nl/docs/api/html/index.html">API reference</a></li>
<li><a href="http://templum.electricmonk.nl/docs/userguide/userguide.html">User guide</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2009/04/26/templum-v020-simple-php-templating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy PEAR Package creation</title>
		<link>http://www.electricmonk.nl/log/2009/04/12/easy-pear-package-creation/</link>
		<comments>http://www.electricmonk.nl/log/2009/04/12/easy-pear-package-creation/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 17:54:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4311</guid>
		<description><![CDATA[Here&#039;s a fairly simple way of creating PEAR package so you can distribute your application or library as a PEAR package. Premise. Let&#039;s assume you&#039;ve written an application or library called &#039;MyApp&#039;. The following is a possible directory structure layout: myapp/ &#124;- MyApp.php \- MyAap/ \- MyApp/MyLib.php Install the PackageFileManager. Since writing a package file [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#039;s a fairly simple way of creating PEAR package so you can distribute your application or library as a PEAR package.</p>
<h2>Premise.</h2>
<p>Let&#039;s assume you&#039;ve written an application or library called &#039;MyApp&#039;. The following is a possible directory structure layout:</p>
<pre>
myapp/
  |- MyApp.php
  \- MyAap/
       \- MyApp/MyLib.php
</pre>
<h2>Install the PackageFileManager.</h2>
<p>Since writing a package file by hand is way too much work, we first install the <tt>PEAR_PackageFileManager</tt> utility. This PEAR package includes a commandline utility which will guide you through the steps needed to create a proper <tt>package.xml</tt> file for your application or library.</p>
<pre>
# <b>pear install pear install PEAR_PackageFileManager_Cli-0.3.0</b>
Ignoring installed package pear/pear
No releases available for package "pear.php.net/install"
Cannot initialize 'channel://pear.php.net/install', invalid or missing package file
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
Did not download optional dependencies: pear/PHP_CompatInfo, use --alldeps to download automatically
pear/PEAR_PackageFileManager can optionally use package "pear/PHP_CompatInfo" (version >= 1.4.0)
downloading PEAR_PackageFileManager_Cli-0.3.0.tgz ...
Starting to download PEAR_PackageFileManager_Cli-0.3.0.tgz (8,051 bytes)
.....done: 8,051 bytes
downloading PEAR_PackageFileManager-1.6.3.tgz ...
Starting to download PEAR_PackageFileManager-1.6.3.tgz (82,393 bytes)
...done: 82,393 bytes
Package "channel://pear.php.net/install" is not valid
install ok: channel://pear.php.net/PEAR_PackageFileManager-1.6.3
install ok: channel://pear.php.net/PEAR_PackageFileManager_Cli-0.3.0
</pre>
<p>If your PEAR is outdated, you will see something like:</p>
<pre>
pear/PEAR_PackageFileManager requires PEAR Installer (version >= 1.8.0alpha1), installed version is 1.7.1
</pre>
<p>In that case, you can upgrade your PEAR like so:</p>
<pre>
# <b>pear channel-update pear.php.net</b>
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
# <b>pear upgrade PEAR</b>
...
upgrade ok: channel://pear.php.net/PEAR-1.8.1
</pre>
<p>You may also run into problems with alpha/beta state packages required for installation of the PackageFileManager CLI package. For instance, I got the following error: <tt>Failed to download pear/XML_Serializer within preferred state "stable", latest release is version 0.19.2, stability "beta", use "channel://pear.php.net/XML_Serializer-0.19.2" to install</tt></p>
<p>In that case, you must manually install the beta packages:</p>
<pre>
# <b>pear install channel://pear.php.net/XML_Serializer-0.19.2</b>
downloading XML_Serializer-0.19.2.tgz ...
Starting to download XML_Serializer-0.19.2.tgz (39,703 bytes)
..........done: 39,703 bytes
downloading XML_Parser-1.3.2.tgz ...
Starting to download XML_Parser-1.3.2.tgz (16,260 bytes)
...done: 16,260 bytes
install ok: channel://pear.php.net/XML_Parser-1.3.2
install ok: channel://pear.php.net/XML_Serializer-0.19.2
</pre>
<h2>Generate a package.xml file.</h2>
<p>You can now use the PackageFileManager command-line utility to bootstrap a <tt>package.xml</tt> file for your PEAR package.</p>
<p>Change to the directory that is the root of your package:</p>
<pre>
$ <b>cd myapp/</b>

myapp$ <b>ls</b>
MyApp  MyApp.php

myapp$ <b>pfm</b>

PEAR Package File Manager Command Line Tool

Please enter the location of your package [.]*: <b>.</b>

Creating a new package file ...

Enter the base install directory*: <b>.</b>

Enter the name of the package [myapp]*: <b>MyApp</b>

Channel or URI based package? [c] (c,u)*: <b>u</b>

Enter the package URI*: <b>http://www.example.com/download/PEAR/</b>

Enter a 1 line summary*: <b>My first PEAR example application.</b>

Enter a description* (2 blank lines to finish):
<b>MyApp is my first PEAR example application.
It rocks.</b>

Enter the release version*: <b>0.1.0</b>

Enter the API version [0.1.0]*: 

Choose a release stability [alpha] (alpha,beta,stable)*:  

Choose an API stability [alpha] (alpha,beta,stable)*: 

Enter any release notes* (2 blank lines to finish):
<b>Initial release</b>

Enter the minimum PHP version [5]*: 

Enter the minimum PEAR Installer version [1.4.0]*: 

Please choose a license from one of the following options

    1) Apache
    2) BSD Style
    3) LGPL
    4) MIT
    5) PHP

Please choose an option: <b>4</b>

How many maintainers?*: <b>1</b>

What type of maintainer is #1? [lead] (lead,developer,contributor,helper)*:     

Enter maintainer #1's name*: <b>Ferry Boender</b>

Enter maintainer #1's username*: <b>fboender</b>

Enter maintainer #1's email [fboender@php.net]*: <b>ferry.boender@example.com</b>

PEAR Package File Manager Command Line Tool

    1. Package name                 [MyApp]
    2. Channel/URI                  [URI: http://www.example.com/download/PEAR/]
    3. Summary                      [My first PEAR example application.]
    4. Description                  [MyApp is my first PEAR example applic...]
    5. Maintainers
    6. Version                      [Release: 0.1.0 API: 0.1.0]
    7. Stability                    [Release: alpha API: alpha]
    8. License                      [MIT]
    9. Notes                        [Initial release]
   10. Dependencies
   11. Tasks
   12. Regenerate contents
   13. Echo package file to stdout
   14. Save &#038; Quit
   15. Quit without saving          (ctrl-c)

Please choose an option from the menu: <b>14</b>

Analyzing MyApp/MyLib.php
Analyzing MyApp.php
</pre>
<p>This generates a <tt>package.xml</tt> for you, containing details for the PEAR package creation. </p>
<h2>Create a PEAR package.</h2>
<p>PEAR can use this <tt>package.xml</tt> file to create a PEAR package for you:</p>
<pre>
myapp$ <b>pear package package.xml </b>
Analyzing myapp/MyApp.php
Analyzing myapp/MyApp/MyLib.php
Package MyApp-0.1.0.tgz done
</pre>
<h2>Testing and (un)installing your package</h2>
<p>Test the installation of the package:</p>
<pre>
myapp$ <b>pear install ./MyApp-0.1.0.tgz</b>
pear install ./MyApp-0.1.0.tgz
install ok: channel://__uri/MyApp-0.1.0
</pre>
<p>It appears to work. Make sure to check the PEAR directory to see if it placed the files in the right spot:</p>
<pre>
myapp$ <b>ls /usr/share/php/</b>
Archive  <i>MyApp</i>      OS    PEAR.php  Structures  adodb  doc   pearcmd.php  php-shell-cmd.php
Console  <i>MyApp.php</i>  PEAR  PHP       System.php  data   docs  peclcmd.php
</pre>
<p>The <tt>MyApp.php</tt> file, and the <tt>MyApp</tt> directory have been added to the PEAR library directory. If their PHP <tt>include_path</tt> is set correctly, users of your package should now be able to include it using:</p>
<pre>
include('MyApp.php');
</pre>
<p>You can uninstall the package using the pear uninstall command:</p>
<pre>
$ <b>pear uninstall channel://__uri/MyApp-0.1.0</b>
uninstall ok: channel://__uri/MyApp-0.1.0
</pre>
<h2>Distribute your package</h2>
<p>You can now put your PEAR package online, and point users to it by mentioning they can install it using PEAR with the command:</p>
<pre>
$ pear install http://www.example.com/download/PEAR/MyApp-0.1.0.tgz
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2009/04/12/easy-pear-package-creation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Templum: Simple PHP Templating</title>
		<link>http://www.electricmonk.nl/log/2009/04/05/templum-simple-php-templating/</link>
		<comments>http://www.electricmonk.nl/log/2009/04/05/templum-simple-php-templating/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 17:52:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[libre software]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4306</guid>
		<description><![CDATA[At the company I work for (ZX), we needed a simple yet powerful templating language for PHP. I googled around a bit for something, but we couldn&#039;t really find anything. So I wrote Templum, and ZX was kind enough to allow me to release it as Open Source under the MIT License. From the Templum [...]]]></description>
			<content:encoded><![CDATA[<p>At the company I work for (<a href="http://www.zx.nl">ZX</a>), we needed a simple yet powerful templating language for PHP. I googled around a bit for something, but we couldn&#039;t really find anything. So I wrote <a href="http://templum.electricmonk.nl">Templum</a>, and ZX was kind enough to allow me to release it as Open Source under the <a href="http://www.opensource.org/licenses/mit-license.html">MIT License</a>.</p>
<p>From the <a href="http://templum.electricmonk.nl">Templum homepage</a>:</p>
<blockquote><p>
Templum is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum is very fast; it approximates native PHP rendering speed for include() statements.
</p></blockquote>
<p>You can install it using PEAR:</p>
<pre>
pear install http://templum.electricmonk.nl/releases/templum-0.1.0.tgz
</pre>
<p>For some examples, check the website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2009/04/05/templum-simple-php-templating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links</title>
		<link>http://www.electricmonk.nl/log/2008/06/18/links/</link>
		<comments>http://www.electricmonk.nl/log/2008/06/18/links/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 14:35:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4037</guid>
		<description><![CDATA[Here are some random links to interesting stuff: FirePHP FirePHP is a PHP debugging library and a Firefox plugin which allow you to output debugging information to the Firebug debugging panel. Since it doesn&#039;t intermingle debugging information with your page output, but writes in a special HTTP header instead, it&#039;s especially useful for AJAX debugging. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some random links to interesting stuff:</p>
<p><b>FirePHP</b><br />
<a href='http://www.firephp.org/'>FirePHP</a> is a PHP debugging library and a Firefox plugin which allow you to output debugging information to the <a href="http://getfirebug.com">Firebug</a> debugging panel. Since it doesn&#039;t intermingle debugging information with your page output, but writes in a special HTTP header instead, it&#039;s especially useful for AJAX debugging. It can also come in handy when you&#039;re trying to debug a server-side script which generates something else than a HTML page. A PDF or PNG file, for example.</p>
<p><b>OpenProj</b><br />
<a href="http://www.openproj.org/openproj">OpenProj</a> is a project management application written in Java and therefor platform independent. It has a lot of the features Microsoft Project has (according to the webpage; I have never used MS Project before, so I wouldn&#039;t know) such as Resources, Gantt Charts, Network Diagrams (PERT Charts), WBS and RBS charts, etc. There are also various different representations of tasks for resources. It doesn&#039;t really outshine Gnome Planner, but at least it&#039;s platform independent.</p>
<p><b>Typechecking Python module</b><br />
<a href='http://oakwinter.com/code/typecheck/'>Typecheck</a> provides powerful run-time typechecking facilities for Python functions, methods and generators. Without requiring a custom preprocessor or alterations to the language, the typecheck package allows programmers and quality assurance engineers to make precise assertions about the input to, and output from, their code. </p>
<p>Here&#039;s a little code example:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@accepts<span style="color: black;">&#40;</span>String, <span style="color: black;">&#91;</span>Number<span style="color: black;">&#93;</span>, <span style="color: black;">&#123;</span><span style="color: #008000;">str</span>: Number<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> my_func<span style="color: black;">&#40;</span>a, <span style="color: #66cc66;">*</span>vargs, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
@accepts<span style="color: black;">&#40;</span>String, Number, Number<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> my_func<span style="color: black;">&#40;</span>a, <span style="color: #66cc66;">*</span>vargs, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2008/06/18/links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Giving up on PHP</title>
		<link>http://www.electricmonk.nl/log/2007/10/05/giving-up-on-php/</link>
		<comments>http://www.electricmonk.nl/log/2007/10/05/giving-up-on-php/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 15:33:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/10/05/giving-up-on-php/</guid>
		<description><![CDATA[I have given up on PHP. I will still need to use it at my job, but in private I refuse to even touch it anymore. Lately, I&#039;ve been busy creating a framework, or a bunch of libraries actually, which where meant to negate some of PHP&#039;s worst qualities. It had better error reporting (the [...]]]></description>
			<content:encoded><![CDATA[<p>I have given up on PHP. I will still need to use it at my job, but in private I refuse to even touch it anymore.</p>
<p>Lately, I&#039;ve been busy creating a framework, or a bunch of libraries actually, which where meant to  negate some of PHP&#039;s worst qualities. It had better error reporting (the kind you can&#039;t just ignore), logging, sane naming schemes, better configurability, etc. But at every turn, it felt like PHP was actively trying to fight my efforts at overcoming its obscene shortcomings. </p>
<p>I will not rehash here those shortcomings of PHP, except that it&#039;s a pathetic excuse for a programming language written by a bunch of particularly bad programmers. The same goes for PEAR. They&#039;re simply horrid.</p>
<p>Some time ago I wrote a little web application in Python, and I actually had fun doing it. It felt liberating not having to fight your programming language every step of the way for once. I revelled in the professionalism with which basically everything in and for Python is constructed. It&#039;s invigorating to work with libraries that aren&#039;t written in a fundamentally broken way just so the authors can use every Design Pattern under the sun. </p>
<p>It&#039;s not strange that Ruby (On Rails) has become so popular. Even though Rails is severely limited in its abilities, people will gladly put up with it because of Ruby. Anybody speaking in favour of PHP compared to Python or Ruby simply hasn&#039;t worked with either Ruby or Python, or has never done anything significant in PHP. Or, like me, where so blinded by how much time they&#039;ve invested in PHP, that they couldn&#039;t and didn&#039;t want to admit what a total piece of crap PHP really is.</p>
<p>Thank you, PHP, for finally exposing yourself as the leper you are. Our ways part here, and may I never run into you again. I&#039;m running off with Python, and we&#039;ll live happily ever after.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/10/05/giving-up-on-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Unexpected SQL Injection</title>
		<link>http://www.electricmonk.nl/log/2007/09/29/4001/</link>
		<comments>http://www.electricmonk.nl/log/2007/09/29/4001/#comments</comments>
		<pubDate>Sat, 29 Sep 2007 08:07:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/09/29/4001/</guid>
		<description><![CDATA[Something every PHP developer should be reading: The Unexpected SQL Injection &#8211; When Escaping Is Not Enough The conclusions: Write properly quoted SQL: Single quotes around values (string literals and numbers) Backtick quotes around identifiers (databases, tables, columns, aliases) Properly escape the strings and numbers: mysql_real_escape_string() for all values (string literals and numbers) intval() for [...]]]></description>
			<content:encoded><![CDATA[<p>Something every PHP developer should be reading: </p>
<p><a href="http://webappsec.org/projects/articles/091007.shtml">The Unexpected SQL Injection &#8211; When Escaping Is Not Enough</a></p>
<p>The conclusions: </p>
<p><blockqoute></p>
<ul style="list-style-type:lower-roman;">
<li>Write properly quoted SQL:</li>
<ol>
<li>Single quotes around values (string literals and numbers)</li>
<li>Backtick quotes around identifiers (databases, tables, columns, aliases)</li>
</ol>
<li>Properly escape the strings and numbers:</li>
<ol>
<li>mysql_real_escape_string() for all values (string literals and numbers)</li>
<li>intval() for all number values and the numeric parameters of LIMIT</li>
<li>Escape wildcard/regexp metacharacters (addcslashes(&#039;%_&#039;) for LIKE, and you better avoid REGEXP/RLIKE)</li>
<li>If identifiers (columns, tables or databases) or keywords (such as ASC and DESC) are referenced in the script parameters, make sure (and force) their values are chosen only as one of an explicit set of options</li>
<li>No matter what validation steps you take when processing the user input in your scripts, always do the escaping steps before issuing the query. Validation is not a substitute for escaping!</li>
</ol>
</ul>
<p></blockqoute></p>
<p>Like my rule #1 of what I like to call Defensive Coding: <i>Don&#039;t be implicit, be explicit</i>. In other words, don&#039;t try to escape things you <i>don&#039;t</i> want in your strings, simply only leave everything you <i>do</i> want in your strings. A column name in a ORDER BY clause should only consist of A-Z, a-z and 0-9. Anything else in the string invalidates that string.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/09/29/4001/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Callback functions in PHP</title>
		<link>http://www.electricmonk.nl/log/2007/09/26/callback-functions-in-php/</link>
		<comments>http://www.electricmonk.nl/log/2007/09/26/callback-functions-in-php/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 20:55:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/09/26/callback-functions-in-php/</guid>
		<description><![CDATA[I was implementing a plugin system for a framework I&#039;m writing, and I needed plugins to be able to register a callback function or method with the Plugin Manager so that the callback function would get called when a signal was emitted. Here&#039;s a very stripped down version of what I ended up with: &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>I was implementing a plugin system for a framework I&#039;m writing, and I needed plugins to be able to register a callback function or method with the Plugin Manager so that the callback function would get called when a signal was emitted. Here&#039;s a very stripped down version of what I ended up with:</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: #666666; font-style: italic;">// Sample callback function</span>
<span style="color: #000000; font-weight: bold;">function</span> callback_function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;callback_function()<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sample class with static and non-static callback functions</span>
<span style="color: #000000; font-weight: bold;">class</span> Callback
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Sample callback method in a class instance</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> callback_method<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Callback-&gt;callback_method()<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Sample static callback method</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> callback_method_static<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Callback::callback_method_static()<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Hook class with which you register callback functions and methods</span>
<span style="color: #666666; font-style: italic;">// which will be called when you call the emit() method.</span>
<span style="color: #000000; font-weight: bold;">class</span> Hook
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$callbacks</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// All the registered callbacks.</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #666666; font-style: italic;">// Register a function/method as a callback function.</span>
	<span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> registerCallback<span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callbacks</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$callback</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #666666; font-style: italic;">// Run all the functions/methods registered as callbacks.</span>
	<span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> emit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callbacks</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$callback</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create a hook class instance with which we will register our</span>
<span style="color: #666666; font-style: italic;">// callbacks.</span>
<span style="color: #000088;">$hook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hook<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Instantiate the sample callback class.</span>
<span style="color: #000088;">$callback</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Register all the sample callbacks with the Hook class instance.</span>
<span style="color: #000088;">$hook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerCallback</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'callback_function'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerCallback</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback_method'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerCallback</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Callback'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback_method_static'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Make the Hook class instance call all the registered callback</span>
<span style="color: #666666; font-style: italic;">// methods.</span>
<span style="color: #000088;">$hook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>First, we set up some sample callback functions and methods (<code>callback_function()</code>, <code>Callback->callback_method()</code> and <code>Callback::callback_method_static()</code>). Then we define the <code>Hook</code> class with which we can register callback functions. Finally, we register our sample callbacks with the Hook class and emit the &#039;signal&#039;. </p>
<p>Right now, there&#039;s only a single signal (or no signal at all, depending on how you look at it), but that&#039;s easy to implement. The magic basically is in the <code>emit()</code> method of the Hook class. It iterates over the registered callbacks, which is nothing  more than an array containing either strings for function callbacks or arrays for static and non-static callback methods. It then calls those using the <code><a href="http://nl3.php.net/call_user_func">call_user_func()</a></code> method.</p>
<p>All this results in the following output, when ran:</p>
<pre>
callback_function()
Callback->callback_method()
Callback::callback_method_static()
</pre>
<p>Nothing fancy, and I must have implemented something similar a gazillion times, but I thought I&#039;d share it with you all.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/09/26/callback-functions-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Configuration hell</title>
		<link>http://www.electricmonk.nl/log/2007/09/02/php-configuration-hell/</link>
		<comments>http://www.electricmonk.nl/log/2007/09/02/php-configuration-hell/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 16:21:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/09/02/php-configuration-hell/</guid>
		<description><![CDATA[From the Apache2 configuration file for host example.com: php_admin_value upload_tmp_dir "/var/www/example.com/tmp/" From the file /var/www/example.com/htdocs/test.php: var_dump(ini_get("upload_tmp_dir")); Output: string(29) "/var/www/example.com/tmp/" Then, after trying to upload a file, from the /var/www/example.com/logs/error.log: [Sun Sep 02 18:09:05 2007] [error] [client 88.211.179.104] PHP Warning: Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/example.com/) in Unknown on [...]]]></description>
			<content:encoded><![CDATA[<p>From the Apache2 configuration file for host example.com:</p>
<pre>
php_admin_value upload_tmp_dir "/var/www/example.com/tmp/"
</pre>
<p>From the file /var/www/example.com/htdocs/test.php:</p>
<pre>
var_dump(ini_get("upload_tmp_dir"));
</pre>
<p>Output:</p>
<pre>
string(29) "/var/www/example.com/tmp/"
</pre>
<p>Then, after trying to upload a file, from the /var/www/example.com/logs/error.log:</p>
<pre>
[Sun Sep 02 18:09:05 2007] [error] [client 88.211.179.104] PHP Warning:  Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/example.com/) in Unknown on line 0, referer: http://example.com/test.php
[Sun Sep 02 18:09:05 2007] [error] [client 88.211.179.104] PHP Warning:  File upload error - unable to create a temporary file in Unknown on line 0, referer: http://example.com/test.php
</pre>
<p>I&#039;ll highlight the important part for you: <tt>open_basedir restriction in effect. File(<b>/tmp</b>) is not within the allowed path(s):</tt>.</p>
<p>The lesson?? PHP needs to <b>STOP</b> silently ignoring errors and stop just using the default value when errors are encountered! The problem was that I specified the wrong upload_tmp_dir. It should have been <tt>/var/www/example.com/htdocs/tmp/</tt>. PHP should have thrown an error because this directory doesn&#039;t exist (it has detected this, because it falls back to the default of <tt>/tmp</tt>) and not just continue.</p>
<p>PHP&#039;s configuration implementation is one of the worst I&#039;ve ever seen, and whoever&#039;s responsible for these kinds of problems should feel ashamed. PHP, like MySQL, is way to lenient when it comes to errors; silently trying to &#039;recover&#039; from them. And people wonder why they&#039;re considered such bad projects?</p>
<p>A tip for PHP&#039;s developers: <i>Fail early and fail loudly</i>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/09/02/php-configuration-hell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim and PHP: tips</title>
		<link>http://www.electricmonk.nl/log/2007/08/31/vim-and-php-tips/</link>
		<comments>http://www.electricmonk.nl/log/2007/08/31/vim-and-php-tips/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 15:01:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/08/31/vim-and-php-tips/</guid>
		<description><![CDATA[I&#039;ve been using Vim for years now, but there&#039;s still new stuff to learn. Check out this page for the PDF version of the slides of a talk given by Andrei Zmievski on editing PHP with Vim. His configuration files are also available. Here&#039;s my favourite list of tips: Add the following text to your [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve been using <a href="http://www.vim.org">Vim</a> for years now, but there&#039;s still new stuff to learn. Check out <a href="http://www.gravitonic.com/blog/archives/000357.html">this page</a> for the <a href="http://www.gravitonic.com/do_download.php?download_file=talks/vancouver-2007/vim-for-php-programmers.pdf">PDF version of the slides</a> of a talk given by Andrei Zmievski on editing <a href="http://www.php.net">PHP</a> with Vim. His <a href="http://www.gravitonic.com/do_download.php?download_file=other/andrei-vim-files.tar.gz">configuration files</a> are also available.</p>
<p>Here&#039;s my favourite list of tips:</p>
<p>Add the following text to your <tt>~/.vim/ftplugin/php.vim</tt> file:</p>
<pre>
set formatoptions+=tcqlro
let php_sql_query=1
let php_htmlInStrings=1
let php_folding = 1
</pre>
<p>This will:</p>
<ul>
<li>Turn on automatic text formatting for PHP so that, for instance, Vim automatically inserts a &#039;*&#039; if you press enter inside a <tt>/* */</tt> comment.</li>
<li>Makes Vim highlight SQL queries in strings.</li>
<li>Makes VIm highlight HTML in strings.</li>
<li>Allows folding on PHP classes and functions. (With the cursor on the first line of a function, press <tt>z-c</tt> to hide the function. <tt>z-o</tt> to show it again. (<b>C</b>lose and <b>O</b>pen the fold)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/08/31/vim-and-php-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

