<?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>Software Bashing &#187; programming</title>
	<atom:link href="http://softwarebashing.org/blog/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://softwarebashing.org/blog</link>
	<description>We hate software. With a passion.</description>
	<lastBuildDate>Sun, 11 Apr 2010 21:04:37 +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 and the great &quot;===&quot; operator</title>
		<link>http://softwarebashing.org/blog/2009/10/php-and-the-great-operator/</link>
		<comments>http://softwarebashing.org/blog/2009/10/php-and-the-great-operator/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 09:57:42 +0000</pubDate>
		<dc:creator>fboender</dc:creator>
				<category><![CDATA[Software Bashing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://softwarebashing.org/blog/?p=268</guid>
		<description><![CDATA[PHP and the great &#034;===&#034; operator.]]></description>
			<content:encoded><![CDATA[<p><a href="http://justimho.blogspot.com/2009/10/php-and-great-operator.html">PHP and the great &#034;===&#034; operator</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwarebashing.org/blog/2009/10/php-and-the-great-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Undefined variables == Undefined behaviour.</title>
		<link>http://softwarebashing.org/blog/2009/09/undefined-variables-undefined-behaviour/</link>
		<comments>http://softwarebashing.org/blog/2009/09/undefined-variables-undefined-behaviour/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 15:17:32 +0000</pubDate>
		<dc:creator>fboender</dc:creator>
				<category><![CDATA[Software Bashing]]></category>
		<category><![CDATA[buggy features]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[stupid features]]></category>

		<guid isPermaLink="false">http://softwarebashing.org/blog/?p=249</guid>
		<description><![CDATA[Here&#039;s a nice one for a PHP exam. Given this complete code example, will it print &#039;aa&#039; or &#039;bb&#039;? &#60;?php if ($variable != 0) { print('aa'); } else { print('bb'); } ?&#62; Let&#039;s apply the rules of logic here. $variable is unset, so it is not &#039;0&#039;. Therefor it should print &#039;aa&#039;. Wrong. Let&#039;s apply the rules of PHP here. [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#039;s a nice one for a PHP exam. Given this complete code example, will it print &#039;aa&#039; or &#039;bb&#039;?</p>
<pre>&lt;?php

if ($variable != 0) {
  print('aa');
} else {
  print('bb');
}

?&gt;</pre>
<p>Let&#039;s apply the rules of logic here. $variable is unset, so it is not &#039;0&#039;. Therefor it should print &#039;aa&#039;.</p>
<p>Wrong.</p>
<p>Let&#039;s apply the rules of PHP here. PHP will <tt style="background-color: #000000; color: #FFFFFF;"> BLACK BOX MAGIC VOODOO </tt> and from that it naturally follows that PHP will print &#039;bb&#039;:</p>
<pre>[todsah@host]~$ php ./magic_voodoo.php

Notice: Undefined variable: variable in /home/todsah/magic_voodoo.php on line 3
bb</pre>
<p>And that, dear PHP developers, is why warnings and notices in PHP should be removed in favour of errors. At. All. Times. I hate PHP.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 143px; width: 1px; height: 1px;">AFMELDING</div>
]]></content:encoded>
			<wfw:commentRss>http://softwarebashing.org/blog/2009/09/undefined-variables-undefined-behaviour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some basic knowledge for you guys</title>
		<link>http://softwarebashing.org/blog/2009/09/some-basic-knowledge-for-you-guys/</link>
		<comments>http://softwarebashing.org/blog/2009/09/some-basic-knowledge-for-you-guys/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 19:30:46 +0000</pubDate>
		<dc:creator>emolenaar</dc:creator>
				<category><![CDATA[Software Bashing]]></category>
		<category><![CDATA[customers]]></category>
		<category><![CDATA[development process]]></category>
		<category><![CDATA[managers]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[protecting users from themselves]]></category>

		<guid isPermaLink="false">http://softwarebashing.org/blog/?p=104</guid>
		<description><![CDATA[Software written by some company for a customer sucks bad most of the times. If you are a &#034;customer&#034;, or some kind of a bloated consultant / account manager, or a project leader, or if you just don&#039;t know how difficult it is to write good software: So. Next time you yell &#034;Dude! How hard can it be to write [...]]]></description>
			<content:encoded><![CDATA[<p>Software written by some company for a customer sucks bad most of the times. If you are a &#034;customer&#034;, or some kind of a bloated consultant / account manager, or a project leader, or if you just don&#039;t know how difficult it is to write good software:</p>
<div id="attachment_105" class="wp-caption aligncenter" style="width: 471px"><img class="size-full wp-image-105  " title="Development explained" src="http://softwarebashing.org/blog/wp-content/uploads/2009/09/software-engineering-explained.png" alt="Development explained" width="461" height="346" /><p class="wp-caption-text">Development explained</p></div>
<p>So. Next time you yell &#034;Dude! How hard can it be to write feature x?&#034; think about it twice.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwarebashing.org/blog/2009/09/some-basic-knowledge-for-you-guys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: The Ultimate Suck</title>
		<link>http://softwarebashing.org/blog/2009/09/php-the-ultimate-suck/</link>
		<comments>http://softwarebashing.org/blog/2009/09/php-the-ultimate-suck/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 14:22:21 +0000</pubDate>
		<dc:creator>fboender</dc:creator>
				<category><![CDATA[Software Bashing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://softwarebashing.org/blog/?p=75</guid>
		<description><![CDATA[I&#039;ve been a PHP developer for too long and it has turned my brain into jelly. PHP is just such a convoluted mess, it rots the brain. I&#039;ve seen other long time PHP programmers with the same syndrome. I&#039;m not sure we&#039;ll ever recover, but there might be a cure. For those who aren&#039;t yet convinced of the level of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve been a PHP developer for too long and it has turned my brain into jelly. PHP is just such a convoluted mess, it rots the brain. I&#039;ve seen other long time PHP programmers with the same syndrome. I&#039;m not sure we&#039;ll ever recover, but there might be a <a href="http://www.python.org">cure</a>. For those who aren&#039;t yet convinced of the level of suckitude of PHP, I&#039;ve compiled a short List Of Stupidity found in PHP.<br />
<span id="more-75"></span></p>
<h2 id="_core_php">Core PHP</h2>
<div class="sectionbody">
<h3 id="_procedural_v_s_object_oriented">Procedural v.s. Object Oriented</h3>
<div class="para">
<p>PHP was procedural. Lately, they&#039;ve started adding Object Oriented things to the core language. We now have a half-procedural, half-Object Oriented PHP. This is a complete mess. It is a paradigm shift with a sincere lack of confidence on the PHP side. Either go for it, or stay with what worked. I&#039;m not talking about allowing PHP users to develop in an Object Oriented methodology. This is fine, and was even done reasonably well. We can now write PHP code Object Oriented, and it works well. I&#039;m talking about the core language here: SPL, the MySQLi library, etc. SPL feels like a half-baked attempt at going in some general direction with PHP, but is just lacks momentum, focus and a clear direction. What is it trying to solve?</p></div>
<div class="para">
<p>What is SPL trying to be? <em>SPL is a collection of interfaces and classes that are meant to solve standard problems.</em>. What kind of <em>problems</em>? It just doesn&#039;t make any sense. It implements all kinds of iterators, but it doesn&#039;t integrate them into the core language at all. What&#039;s wrong with <tt>foreach</tt>? Is SPL something for the future of PHP? If so, then keep it under wraps until that future is here. Don&#039;t expose it before it&#039;s done.</div>
<div class="para">
<p>SPL&#039;s data structures are cute, but why should I use them? Why use SPLStack, if I&#039;ve already got arrays in PHP? The ArrayIterator.. what is its purpose? I can create an ArrayObject from an array, and then iterate over it by requesting an ArrayIterator from it and calling the <tt>next()</tt> method on that. I can also <strong>NOT</strong> do that, and just call <tt>foreach()</tt> which is much cleaner. The whole of SPL seems to serve no other purpose than to make PHP appear more like Java.</div>
<div class="para">
<p>The really bad thing about SPL is that they once again managed to screw it up by adding procedural functions to an otherwise entirely Object Oriented interface: SPL functions. PHP is really showing it&#039;s identity crisis. It&#039;s trying to be a kind of PERL and do everything magically. It&#039;s trying to be Java, by doing things Object Oriented and over-engineered. It&#039;s trying to do things like C, the procedural way. And like everything that tries to be like everything, it fails at all of them.</p></div>
<div class="para">
<p><strong>solution</strong>: Remove SPL and all things Object-Oriented (in the Core) or focus on SPL and Object-Orientation and integrate it into the core language.</div>
<h3 id="_aliases">Aliases</h3>
<div class="para">
<p>The PHP library is filled with all kinds of function aliases. Why? There is no point, other than to cause confusion and unreadable code. I mean, <tt>is_int()</tt> and <tt>is_integer()</tt>? <tt>join()</tt> and <tt>implode()</tt>. Really. Get that crap out of there.</div>
<div class="para">
<p><strong>solution</strong>: Remove all aliases.</div>
<h3 id="_shebang">Shebang</h3>
<div class="para">
<p>Just about every script under the UNIX operating system can be made executable by changing the permissions and adding a simple line at the top of the script that tells the shell what interpreter it should use to run the file. This line is called a shebang, and it works like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>[todsah@jib]~$ cat file.php
#!/usr/bin/php
&lt;?php
echo("hoi\n");
?&gt;
[todsah@jib]~$ chmod 755 ./file.php
[todsah@jib]~$ ./file.php
hoi</tt></pre>
</div>
</div>
<div class="para">
<p>The shell &#039;magically&#039; understands how the script should be run, and it thus starts the PHP interpreter to interpret the script. This is basically the same as running this manually:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>[todsah@jib]~$ /usr/bin/php ./file.php
hoi</tt></pre>
</div>
</div>
<div class="para">
<p>PHP didn&#039;t used to have this ability, but the PHP development team hacked it in, and now it does. Completely in the style of the rest of PHP, it was implemented shoddy and without much forefought. You see, when we create a file <tt>main.php</tt>, and include the file <tt>file.php</tt> in that file, here&#039;s what happens:</div>
<div class="listingblock">
<div class="content">
<pre><tt>[todsah@jib]~$ cat main.php
#!/usr/bin/php
&lt;?php
include('file.php');
?&gt;
[todsah@jib]~$ chmod 755 ./main.php
[todsah@jib]~$ ./main.php
#!/usr/bin/php
hoi</tt></pre>
</div>
</div>
<div class="para">
<p>You see? The PHP interpreter understands the shebang, but it only understands it in files directly ran from the shell, and not when you include/require it from another file. This makes it impossible to do cool stuff such as making PHP files self-executable so that when ran from the commandline it will run a bunch of self-tests, but if you include it, it will just skip over the test and only get included. Awesome work PHP.</p></div>
</div>
<h2 id="_datatypes">Datatypes</h2>
<div class="sectionbody">
<h3 id="_associative_arrays">Associative arrays</h3>
<div class="para">
<p>PHP&#039;s associative arrays, sometimes better known as hashmaps, allow for both indexed access as well as hashed access in the <strong>same</strong> array. This gives rise to strange, mixed arrays such as:</div>
<div class="listingblock">
<div class="content">
<pre><tt>&lt;?php
$a = array(
);
$a[0] = 'abc';
$a['somekey'] = 'def';
$a[3] = 'ghi';
$a['foo'] = 'jkl';

var_dump($a);
?&gt;

output:

array(4) {
  [0]=&gt;
  string(3) "abc"
  ["somekey"]=&gt;
  string(3) "def"
  [3]=&gt;
  string(3) "ghi"
  ["foo"]=&gt;
  string(3) "jkl"
}</tt></pre>
</div>
</div>
<div class="para">
<p>Datastructures are <strong>the most</strong> important part of any programming language. Allowing such mixing as we see above is foolish, as it makes it easy to create a complete mess of arrays and causes very strange behaviour:</div>
<div class="listingblock">
<div class="content">
<pre><tt>&lt;?php
$a = array();
$a[0] = 'abc';
$a[1] = 'def';
$a[2] = 'ghi';

$data = 'xyz123';
for ($i = 0; $i &lt; strlen($data); $i++) {
        $a[ $data[$i] ] = $i;
}
var_dump($a);
?&gt;

output:
array(7) {
  [0]=&gt;
  string(3) "abc"
  [1]=&gt;
  int(3)
  [2]=&gt;
  int(4)
  ["x"]=&gt;
  int(0)
  ["y"]=&gt;
  int(1)
  ["z"]=&gt;
  int(2)
  [3]=&gt;
  int(5)
}</tt></pre>
</div>
</div>
<div class="para">
<p>PHP made it&#039;s associative arrays <strong>too</strong> powerful. Now, they become a mess.</div>
<div class="para">
<p><strong>solution</strong>: Put the PHP authors through a computer science study. Next, seperate current array functionality into normal tuples (array), sets and hashmaps. Also, do not cast string hashmap keys to int if possible. int(0) and str(<em>0</em>) are <strong>not</strong> the same.</div>
</div>
<h2 id="_error_reporting">Error reporting</h2>
<div class="sectionbody">
<h3 id="_error_level">Error level</h3>
<div class="para">
<p>Currently PHP allows developers to set the level of errors they want to display or ignore complete. This is bad practice. Developers will switch off errors and warnings because they&#039;re lazy, especially novice programmers. This often happens when some third-party library (especially everything in PEAR) starts displaying warnings or errors, and the developer turns off error reporting to get rid of them. There is no easy way to exclude the displaying of errors and warning from certain origins, so developers quickly resort to turning them off globally.</p></div>
<div class="para">
<p><strong>solution</strong>: Remove error reporting levels alltogether. Always display and log <strong>every</strong> warning and error. This will break every package in PEAR, which doesn&#039;t matter because PEAR is a flaming heap of shit anyway.</div>
<h3 id="_error_severity">Error severity</h3>
<div class="para">
<p>PHP is not conservative enough about classifying its warnings and errors:</p></div>
<div class="ilist">
<ul>
<li>An undefined variable is currently a notice.</li>
<li>An undefined property is currently a notice.</li>
<li>Using foreach() on something which isn&#039;t an array or class instance is currently a warning.</li>
<li>Etc…</li>
</ul>
</div>
<div class="para">
<p>This is remendously stupid, and as such has given rise to a wide variety of insecurities in PHP applications. This is PHP&#039;s fault, it should protect the developer from itself, and the users from the developers. An undefined variable should always be a critical error. All of the examples above are programmer errors, and the programmer should be made aware of this.</p></div>
<div class="para">
<p><strong>solution</strong>: Everything should be a fatal error, except for Deprecation warnings.</div>
<h3 id="_error_destination">Error destination</h3>
<div class="para">
<p>PHP can send errors to too many destinations. They can be displayed in the output, or not. They can go the Apache error log, or not. They can go to a seperate PHP error log, or not. Repeated errors can be ignored or not. Errors can be sent to the standard out (STDOUT) or standard error (STDERR) or to nowhere at all. As you can see, this quickly becomes an enormous mess. But it gets worse:</p></div>
<div class="para">
<p>There are too many things that can influence how errors are handled. The global php.ini can change the behaviour. Then the Apache configuration can include PHP configuration changes. Some things can be changed in htaccess configurations. Then there can be multiple php.ini&#039;s depending on how you&#039;re running PHP: Commandline, CGI or mod_php. Finally, PHP scripts can <strong>at any time</strong> change their error logging behaviour.</div>
<div class="para">
<p>All this makes such a mess of PHP error reporting, it&#039;s no wonder most developers simply shut the entire thing off.</p></div>
<div class="para">
<p><strong>solution</strong>: Always report all errors and warnings in the output and log them to standard out. They will appear in the output and in the Apache error logs.</div>
<h3 id="_exceptions_v_s_native_errors">Exceptions v.s. Native errors</h3>
<div class="para">
<p>Why are some things exceptions, and other things native PHP warnings/errors? SPL throws exceptions, the rest all just .. log errors. They&#039;re not even really errors.</p></div>
<h3 id="_error_messages">Error messages</h3>
<div class="para">
<p>Some error messages in PHP are so cryptic, you actually need to speak hebrew to understand them. For instance, if you make an error in the scope resolution operator (<tt>::</tt>) in PHP, you get this:</div>
<div class="listingblock">
<div class="content">
<pre><tt>Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in Command line code on line 1</tt></pre>
</div>
</div>
<div class="para">
<p>PHP&#039;s developers are completely aware of this error message, it&#039;s confusing nature and that it causes programmers writing in PHP unnecessary head-aches, yet they refuse to remove it from PHP. Now, there&#039;s nothing wrong with some humor in your programming language, but it should never come at the expense of your user base.</p></div>
<div class="para">
<p>This is a perfect embodiment of everything that&#039;s wrong with PHP as a language, and the team of developers creating the PHP language.</p></div>
</div>
<h2 id="_databases">Databases</h2>
<div class="sectionbody">
<h3 id="_database_access_layer">Database access layer</h3>
<div class="para">
<p>There is no native general database access layer in PHP. They took the lazy approach, and simply dumped every C connector library they could find into the PHP core without writing any kind of wrapper around them. There is nothing wrong with directly accessible native C connector libraries for databases, but they should only be used if you need very very raw speed. Instead, they are the default way of connecting to databases in PHP. Every database connector uses a different approach to connecting, querying, cursors, error reporting, etc.</p></div>
<div class="para">
<p>Since this is such as mess, people have decided to do something about it. Now we have about four PEAR packages which try to solve the problem, two of which seem to have been deprecated and the rest being buggy, slow, incomprehensable, over-engineered and PEARy in general. We have DBx. Oh, wait, that&#039;s been moved to PECL and isn&#039;t included with PHP by default anymore, in effect deprecating it. We have ODBC, but hold on, it&#039;s not really ODBC: &#034;Note: With the exception of iODBC, there is no ODBC involved when connecting to the above databases. The functions that you use to speak natively to them just happen to share the same names and syntax as the ODBC functions&#034;. The latest thing seems to be PDO which, for a change, looks like somebody really thought about. Unfortunatelly, it&#039;s only available in PHP 5.1. For PHP 5.0 you need to compile a PECL extension. But we can live with that. PDO works reasonable however, like so many things in PHP, it&#039;s error reporting is a complete dragon to work with.</p></div>
<div class="para">
<p><strong>solution</strong>: Provide one single database access layer (PDO). Remove all the others. Find a way to discourage users from directly using the native connectors. Fix the error reporting for all connectors.</div>
<h3 id="_mysql_i_connectors">MySQL(i) connectors</h3>
<div class="para">
<p>Now, the native MySQL connectors are a complete mess. It seems to be the only connector which allows you to define how it should connect from the php.ini. There are too many ways to escape query parameters. It does not support prepared statements. For this we have MySQLi (ironically stands for MySQL Improved), which is an even bigger mess. MySQLi is not backwards compatible with the old MySQL connectors, meaning you&#039;ll have to complete rewrite every portion of your application that uses the old connector. The MySQLi connector is half Object-Oriented, half procedural style. Why this is, nobody knows. All we know is it creates a mess in the API. When looking at the API documentation, it seems we&#039;ve got a procedural style method for each corresponding Ojbect-Oriented style method. However, they behave in completely different ways. Or at least the error methods do, which is the only thing I tried before deciding that MySQLi is not worth my time. Another funny thing about the MySQLi connector is that you have to manually determine how query parameters in prepared statements have to be escaped. Another future security nightmare for PHP applications.</p></div>
<div class="para">
<p><strong>solution</strong>: Deprecate the old MySQL extension immediately. Remove the procedural versions of MySQLi. Implement real prepared statement parameter escaping. Fix error reporting. Remove all mentionings of the old mysql connector from all documentation. Pretend it never existed.</div>
</div>
<h2 id="_pear">PEAR</h2>
<div class="sectionbody">
<h3 id="_package_versions">Package versions</h3>
<div class="para">
<p>PEAR has too many deprecated packages. I&#039;m not sure what&#039;s going on here, but many of the same packages have two, three sometimes even four different implementations. For instance, there are two Auth_PrefManager packages: Auth_PrefManager and Auth_PrefManager2. In full-on PHP style, it&#039;s <strong>not</strong> version 2 you should be using, because that&#039;s been deprecated. It&#039;s version 1 you should use because, get this, PrefManager2 was an experimental package! How did an experimental package get into PEAR and, much more importantly, what&#039;s it still doing in there?</div>
<div class="para">
<p>This is a very common occurence in the PEAR package repository. Take the database packages for instance. First we note that there are two (or more?) completely different Object Interface packages in PEAR. Next, there&#039;s a Database abstraction layer DB. This was created before PDO even existed, which is good, but it never really worked. It was always extremely buggy, throwing errors and warnings all over the place. It&#039;s been deprecated (but of course, it&#039;s still listed in the PEAR repository). It hints that we should use MDB2. Apparently, MDB v1 failed miserably, like every other PEAR package. I&#039;m not too confident that MDB2 is going to make it too, for some reason. MDB2 seems to replicate a lot of the behaviour of native PHP extensions, various PECL extensions and a whole slew of other PEAR packages. So what do I use? I just have <strong>no</strong> idea. And more importantly, if I decide on choice X, how am I going to be sure that it won&#039;t be deprecated in two weeks, like all those other PHP and PEAR packages?</div>
<div class="para">
<p>Now, there&#039;s nothing wrong with choice, of course. There isn&#039;t even anything wrong with duplicated efforts. We see this in every language, and it&#039;s always okay. But for some reason that I can&#039;t quite put my finger on, it fails miserably in PHP and PEAR.  PEAR tries to be the authoritive end-point for useful collections of PHP libraries, but it just fails, hard.</p></div>
<div class="para">
<p>There just doesn&#039;t seem to be <strong>any</strong> kind of consensus in the PHP world about which direction they should be going. Should they focus in PDO? Should such database abstraction libraries be packaged in PEAR or on PHP or in PECL or in the user-contributed notes in the documentation? They just don&#039;t know, they have no direction whatsoever. As such, they move in all directions at the same time, and PHP developers stick with using the mysql C connector because it&#039;s the only thing that appears to be stable.</div>
<div class="para">
<p><strong>solution</strong>: Deprecate PEAR entirely. Let evolution sort things out without any kind of central control. PEAR should either be a clean repository of recommended packages, or should be an easy-to-install-PHP-libraries distribution net where everybody can upload their crap.</div>
<h3 id="_quality_assurence">Quality Assurence</h3>
<div class="para">
<p>For some reason the people who do <em>Quality Assurence</em> (and I use that term as lightly as I possibly can) for PEAR have it in their head that as long as your <tt>if</tt> statements have a space between the <tt>if</tt> and the opening parenthesis, they&#039;ve done their job. Wrong. Quality Assurence in PEAR is a complete atrocity. Old cruft isn&#039;t cleaned up, there&#039;s no advice about duplicated efforts at all. They allow all kinds of idiotic packages in (a LinkedList implementation in PHP.. please).</div>
<div class="para">
<p><strong>solution</strong>: Deprecate PEAR entirely. Let evolution sort things out without any kind of central control. PEAR should either be a clean repository of recommended packages, or should be an easy-to-install-PHP-libraries distribution net where everybody can upload their crap.</div>
<h3 id="_errors">Errors</h3>
<div class="para">
<p>Too many packages in PEAR have errors and warnings. There&#039;s not much too say about this. PEAR packages are all unusable because of this. They can&#039;t be trusted.</p></div>
<div class="para">
<p>Now, this isn&#039;t really the PEAR package authors fault. PHP&#039;s error reporting facilities are such a pain in the ass that it&#039;s incredibly hard to write code that doesn&#039;t trigger any errors. In fact, depending on what you&#039;re doing, it&#039;s impossible.</p></div>
<div class="para">
<p><strong>solution</strong>: Deprecate PEAR entirely, or put true quality assurence on the packages (and fix PHP&#039;s error reporting mechanism). Everything should run on PHP 5.0+ without <strong>any</strong> errors, warnings, notices, strange hacks, etc.</div>
</div>
<h2 id="_core_library">Core library</h2>
<div class="sectionbody">
<h3 id="_regular_expressions">Regular expressions</h3>
<div class="para">
<p>There are two libraries for regular expressions. There should be only one.</p></div>
<div class="para">
<p><strong>solution</strong>: Remove one of the two regular expression packages. Preferably ereg. Rename preg to <tt>regexp</tt> &#8211; nobody gives a shit whether it came from PERL or Extended POSIX.</div>
<h3 id="_isset">isset()</h3>
<div class="para">
<p><tt>isset()</tt> sounds like it checks whether a variable is defined in the current (or even global) scope. PHP&#039;s manual says: <em>Determine whether a variable is set. </em>. Naturally, that&#039;s not really what it does. Rather, <tt>isset()</tt> checks if a variable has a value other than NULL, without giving an error if the variable isn&#039;t set. You&#039;d think the following returns <tt>True</tt>:</div>
<div class="listingblock">
<div class="content">
<pre><tt>$foo = NULL;
if(isset($foo)) {
  print('\$foo is set');
}
# No output</tt></pre>
</div>
</div>
<div class="para">
<p>Of course, this is not a terrible disaster. But many people use <tt>isset()</tt> to check for array keys (<tt>$a = array(<em>a</em> ⇒ NULL); isset($a[<em>a</em>]) == False</tt>). Now what happens when you select fields from a database, retrieve the results with <tt>db_fetch_assoc()</tt>, and one of the values is <tt>NULL</tt>? Do you know? I can&#039;t guess what happens in PHP, so I&#039;d have to experiment. Or just always use <tt>array_key_exists()</tt>. Another complete failure of PHP at being a predictable language.</div>
<h3 id="_language_constructs_v_s_functions">Language constructs v.s. functions</h3>
<div class="para">
<p>PHP is easily confused when it comes to what is a function and what is a function. You see, some things in PHP <em>appear</em> as a function, but they really aren&#039;t. They&#039;re <em>language constructs</em>. The difference between this is a long and boring story which shouldn&#039;t really have to matter to programmers writing code in PHP. It is enough to know that the PHP developers are sufficiently saddistic to make it basically impossible for PHP programmers to see the difference, nor to create proper errors for their &#039;misuse&#039;.</div>
<div class="para">
<p>Here are some nice effects of language constructs that appear to be functions, but really aren&#039;t:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>var_dump(empty(trim($name)));
Fatal error: Can't use function return value in write context in file.php on line 1</tt></pre>
</div>
</div>
<div class="para">
<p>An obvious error, I&#039;d say. Fortunatelly the PHP developers <em>know</em> that what you really want to do, and understand the confusion completely. Instead of just making empty() a function, they&#039;ve opted to document their own mental retardedness here: <a href="http://nl3.php.net/manual/en/function.empty.php">http://nl3.php.net/manual/en/function.empty.php</a></div>
<div class="listingblock">
<div class="content">
<pre><tt>var_dump(empty(''));
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '$' in file.php on line 1</tt></pre>
</div>
</div>
<div class="para">
<p>Another fun thing to try:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$foo = 'bar';
var_dump(function_exists('empty'));
// output: false
var_dump(empty($foo));
// output: true</tt></pre>
</div>
</div>
<div class="para">
<p>PHP&#039;s identity crisis becomes apparent again as <tt>function_exists</tt> fails to detect PHP&#039;s own functions because they&#039;re not functions but language constructs although they look and act (almost) completely like functions. Kudos for PHP.</div>
<h3 id="_error_success">Error: Success!</h3>
<div class="para">
<p>Some functions work just brilliantly:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Testing XMLRPC server is operating...: Couldn't contact the XMLRPC server. (PHP reported: 'file_get_contents(http://ems2.dev.local/svcmon/RPC/server.php) [function.file-get-contents]: failed to open stream: Success')</tt></pre>
</div>
</div>
<div class="para">
<p>The URL works just fine. PHP simply reports an error about the thing it tried was succesful.</p></div>
<h3 id="_api_confusion">API confusion</h3>
<div class="para">
<p>PHP has a highly confusing API. Without even looking at the mixing of objects, functions and language constructs, even its simple function parameters are often mixed up and confusing.</p></div>
<h4 id="_pathinfo">pathinfo</h4>
<div class="para">
<p>The <tt>pathinfo()</tt> function can take option parameters which are constants in the form of <tt>PATHINFO_DIRNAME</tt>, etc. One would naturally assume that you could then also do:</div>
<div class="listingblock">
<div class="content">
<pre><tt>$pathparts = pathinfo($path, PATHINFO_DIRNAME);
print($pathparts[PATHINFO_DIRNAME]);</tt></pre>
</div>
</div>
<div class="para">
<p>But this doesn&#039;t work, as the indexes of the array that pathinfo() returns are strings (<em>dirname</em>) instead of integers that correspond to the constants. It&#039;s clear that this function was written by a programming noob that doesn&#039;t understand the use of constants, nor how to build a consistent API.</div>
</div>
<h2 id="_documentation">Documentation</h2>
<div class="sectionbody">
<h3 id="_user_contributed_notes">User contributed notes</h3>
<div class="para">
<p>The user contributed notes in PHP&#039;s documentation are an attrocity, and they need to go. We all know and appreciate the &#034;No documentation is better than bad documentation&#034; principle, and PHP&#039;s documentation would do wise to keep the buggy, incorrect, asinine, slow, sloppy, worthless craptasticly FUBARred code PHP programmers seem to love out of the official documentation, or at the very least filter out any example code and &#034;Hey guys look, I made my own version of X!&#034; kind of code.</p></div>
<div class="para">
<p>The user contributed notes should only ever refer to incorrect or missing information in the documentation itself. User contributed examples should go to ActiveState-like code repositories or, preferably, the waste-bin in case of PHP.</p>
<h2 id="_core_library">Conclusion</h2>
<p>There&#039;s more, but I can&#039;t go on anymore. I can&#039;t even muster enough brain-goo to write up a conclusion. Do I really need to? Goodbye cruel PHP world, it&#039;s been a torture!</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://softwarebashing.org/blog/2009/09/php-the-ultimate-suck/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.425 seconds -->

