<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.robnugen.com/w/index.php?action=history&amp;feed=atom&amp;title=Programming%3ATerrible_code</id>
	<title>Programming:Terrible code - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.robnugen.com/w/index.php?action=history&amp;feed=atom&amp;title=Programming%3ATerrible_code"/>
	<link rel="alternate" type="text/html" href="https://wiki.robnugen.com/w/index.php?title=Programming:Terrible_code&amp;action=history"/>
	<updated>2026-04-06T23:25:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.robnugen.com/w/index.php?title=Programming:Terrible_code&amp;diff=402&amp;oldid=prev</id>
		<title>Thunderrabbit: terrible code I found at work</title>
		<link rel="alternate" type="text/html" href="https://wiki.robnugen.com/w/index.php?title=Programming:Terrible_code&amp;diff=402&amp;oldid=prev"/>
		<updated>2008-06-03T06:01:36Z</updated>

		<summary type="html">&lt;p&gt;terrible code I found at work&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;3 June 2008&lt;br /&gt;
&lt;br /&gt;
Bad news: broken chdir&lt;br /&gt;
&lt;br /&gt;
[[Image:warning chdir- no such file etc on line 283.png]]&lt;br /&gt;
&lt;br /&gt;
Worse news: continuing after broken chdir&lt;br /&gt;
&lt;br /&gt;
[[Image:file list after not checking broken chdir on line 283.png]]&lt;br /&gt;
&lt;br /&gt;
I saw the above, so I was like, WTF? and went to find the code below, which runs on our live server.  The same code runs on our test server which uses different data.  And runs on our other test server which uses a different directory structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
// snip&lt;br /&gt;
&lt;br /&gt;
$cwd = getcwd();&lt;br /&gt;
chdir(&amp;#039;/var/apache/ssl/htdocs/admin/csv/user/&amp;#039;);&lt;br /&gt;
$fileList = array();&lt;br /&gt;
$dateList = array();&lt;br /&gt;
&lt;br /&gt;
if ($dir = opendir(&amp;quot;.&amp;quot;)) {&lt;br /&gt;
       $i = 0;&lt;br /&gt;
       while (false !== ($file = readdir($dir))) {&lt;br /&gt;
               if ($file != &amp;quot;.&amp;quot; &amp;amp;&amp;amp; $file != &amp;quot;..&amp;quot;) {&lt;br /&gt;
                       $fileList[$i] = $file;&lt;br /&gt;
                       $dateList[$i] = date(&amp;quot;Y/m/d H:i:s&amp;quot;, fileatime($file));&lt;br /&gt;
                       $i++;&lt;br /&gt;
               }&lt;br /&gt;
       }&lt;br /&gt;
       closedir($dir);&lt;br /&gt;
}&lt;br /&gt;
chdir($cwd);&lt;br /&gt;
&lt;br /&gt;
// snip&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are some redeeming qualities to this code:&lt;br /&gt;
&lt;br /&gt;
# it&amp;#039;s indented per block level&lt;br /&gt;
# it doesn&amp;#039;t allow . nor .. to be processed&lt;br /&gt;
# it closes its file handle $dir&lt;br /&gt;
# it saves and restores its working directory after it&amp;#039;s done.&lt;br /&gt;
&lt;br /&gt;
There are also, however, a couple of points that are not as redeeming.&lt;br /&gt;
&lt;br /&gt;
# hard coding &amp;#039;/var/apache/ssl/htdocs/admin/csv/user/&amp;#039;&lt;br /&gt;
# not checking to see if the hard code worked&lt;br /&gt;
&lt;br /&gt;
In preparing to fix them, I found this, or should I say &amp;#039;&amp;#039;these&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
[[Image:omg a whole slew of hardcoded paths.png]]&lt;/div&gt;</summary>
		<author><name>Thunderrabbit</name></author>
	</entry>
</feed>