<?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>Giedrius Majauskas blog &#187; php</title>
	<atom:link href="http://www.majauskas.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.majauskas.com</link>
	<description></description>
	<lastBuildDate>Thu, 29 Jul 2010 08:34:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Stop cursing PHP for your faults</title>
		<link>http://www.majauskas.com/stop-cursing-php-for-your-faults</link>
		<comments>http://www.majauskas.com/stop-cursing-php-for-your-faults#comments</comments>
		<pubDate>Thu, 03 Sep 2009 16:10:17 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software quality]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=224</guid>
		<description><![CDATA[I have read a tweet about PHP programming today that made me furious. “Handling complex logic in PHP is like doing the LSATs after shock therapy” What is wrong with this statement? It moves responsibility from coder to the coding language and that is completely wrong in this case. Firstly, PHP has syntax similar to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fstop-cursing-php-for-your-faults"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fstop-cursing-php-for-your-faults&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I have read a tweet about PHP programming today that made me furious.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">“Handling complex logic in PHP is like doing the LSATs after shock therapy”</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">What is wrong with this statement? It moves responsibility from coder to the coding language and that is completely wrong in this case.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Firstly, PHP has syntax similar to C, which is used to code programs much more complex than most of websites. Almost all control statements are similar or same.  Although there are differences, I doubt anyone would argue that there is a significant lack of logic control statements in PHP than in C. Although PHP lacks specific PC programming libraries, it has very little to do with implementing logic of application.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">So, what might cause such statements?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The top reason for problems handling logic is bad quality of the code (software quality measures how well software is designed (quality of design), and how well the software conforms to that design (quality of conformance), although there are several different definitions). PHP, similarly to C, is a very flexible language. And you need to and think work to produce good, quality code.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thus, what is code quality characteristics related to implementing logic in PHP?</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1.<span style="white-space: pre;"> </span>Separation of concerns. You should not handle logic, input, output, database, exceptions in single big file. Implement these as functions, or use libraries and frameworks. There is no excuse to not use a PHP framework nowadays, except when modifying old application source. And yes, I made such mistakes myself in the past.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2.<span style="white-space: pre;"> </span>Avoid logic shortcuts, like die(), exit() and break (in cycles, not in switch) statements if you can. They make code much harder to comprehend in the long run. Perfect function or method has a single return statement as well.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3.<span style="white-space: pre;"> </span>Use right model of computation to process information gathered. Logic will look nasty in all the languages as long as you have no foundation how to handle it. And the worst is, these programming models are already here for decades, like FSMs. Simply, they are used in software programming, but not so in web programming.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4.<span style="white-space: pre;"> </span>Comments, documentation, sane names of variables and no hacking. One of the reasons for bad code is “quick fixes”, when quick, undocumented fixes are applied to program code that no one understands later on. Even worse, they are applied to the system/framework core without any documenting sometimes. That might leave you stuck with un-updated version of some framework for long time.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5.<span style="white-space: pre;"> </span>It is better to comply with framework programming model than implement couple different models in single system. If you are using hook and plugin based framework as wordpress, stick to it, and know its features, internal logic and limitations.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">If you will know these 5 things, all you will have to curse is your code or framework/cms you are using. But not the PHP.</div>
<p>“Handling complex logic in PHP is like doing the LSATs after shock therapy”</p>
<p>What is wrong with this statement? It moves responsibility from coder to the coding language and that is completely wrong in this case.</p>
<p>Firstly, PHP has syntax similar to C, which is used to code programs much more complex than most of websites. Almost all control statements are similar or same.  Although there are differences, I doubt anyone would argue that there is a significant lack of logic control statements in PHP than in C. Although PHP lacks specific PC programming libraries, it has very little to do with implementing logic of application.</p>
<p>So, what might cause such statements?</p>
<p>The top reason for problems handling logic is bad quality of the code (<a href="http://en.wikipedia.org/wiki/Software_quality">software quality measures how well software is designed (quality of design), and how well the software conforms to that design (quality of conformance)</a>). PHP, similarly to C, is a very flexible language. And you need to and think work to produce good, quality code.</p>
<p>Thus, what is code quality characteristics related to implementing logic in PHP?</p>
<ol>
<li>Separation of concerns. You should not handle logic, input, output, database, exceptions in single big file. Implement these as functions, or use libraries and frameworks. There is no excuse to not use a PHP framework nowadays, except when modifying old application source. And yes, I made such mistakes myself in the past.</li>
<li>Avoid logic shortcuts, like die(), exit() and break (in cycles, not in switch) statements if you can. They make code much harder to comprehend in the long run. Perfect function or method has a single return statement as well.</li>
<li>Use right model of computation to process information gathered. Logic will look nasty in all the languages as long as you have no foundation how to handle it. And the worst is, these programming models are already here for decades, like FSMs. Simply, they are used in software programming, but not so in web programming.</li>
<li>Comments, documentation, sane names of variables and no hacking. One of the reasons for bad code is “quick fixes”, when quick, undocumented fixes are applied to program code that no one understands later on. Even worse, they are applied to the system/framework core without any documenting sometimes. That might leave you stuck with un-updated version of some framework for long time.</li>
<li>It is better to comply with framework programming model than implement couple different models in single system. If you are using hook and plugin based framework as wordpress, stick to it, and know its features, internal logic and limitations.</li>
</ol>
<p>If you will know these 5 things, all you will have to curse is your code or framework/cms you are using. But not the PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/stop-cursing-php-for-your-faults/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>5 things to look at when comparing php frameworks</title>
		<link>http://www.majauskas.com/things-to-look-at-when-comparing-php-frameworks</link>
		<comments>http://www.majauskas.com/things-to-look-at-when-comparing-php-frameworks#comments</comments>
		<pubDate>Thu, 11 Jun 2009 15:38:13 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=152</guid>
		<description><![CDATA[I had read a post at sitepoints about 16 php 5 frameworks. I will not argue the fact that frameworks are good and you should use one. What saddens me is that the key points of comparison are omitted in the post. So, how to compare different php 5 frameworks? Let us see. 1. Paradigms [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fthings-to-look-at-when-comparing-php-frameworks"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fthings-to-look-at-when-comparing-php-frameworks&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I had read a post at <a href="http://www.sitepoint.com/blogs/2009/06/09/16-php-frameworks/">sitepoints about 16 php 5 frameworks</a>. I will not argue the fact that frameworks are good and you should use one. What saddens me is that the key points of comparison are omitted in the post.</p>
<p>So, how to compare different php 5 frameworks? Let us see.</p>
<p>1.	Paradigms used. Although MVC is mainstream now, it is not a single paradigm in php development. There are frameworks that are event based only. Additionally, there are different paradigms for different application layers, for example <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> for database (model) layer, pretty well supported in php cake.  Zend does not have module layer at all, you need to use your own database access, as example.</p>
<p>2.	Modularity and reusability of framework. Although MVC provides modularity on controller- basis, additional modularity is required to re-use code between applications. This is important for developing bigger project that share modules.</p>
<p>3.	Php version support.  Some frameworks require specific versions of php5. This means that you have limited options for hosting.</p>
<p>4.	Shared hosting support. You might need that before project kicks in. Some frameworks behave weirdly on shared hosting, as they need specific setup.</p>
<p>5.	Proof of concept and maturity. Have you seen applications developed with the framework? Is framework developer community active or dormant? I would shun a framework without some real-world example sites.</p>
<p>Have something to add? Comment bellow!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/things-to-look-at-when-comparing-php-frameworks/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to write non-sucking voting script</title>
		<link>http://www.majauskas.com/how-to-write-non-sucking-voting-script</link>
		<comments>http://www.majauskas.com/how-to-write-non-sucking-voting-script#comments</comments>
		<pubDate>Sun, 29 Mar 2009 23:03:32 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[voting]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=118</guid>
		<description><![CDATA[Voting is quite basic element of any site that claims to be social. This is a basic tool to get opinion of visitors on topics and works as viral marketing too. However, sooner or later your visitors will question if your script is secure enough to avoid fake voting bots. So let&#8217;s cover couple ways [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-to-write-non-sucking-voting-script"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fhow-to-write-non-sucking-voting-script&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>Voting is quite basic element of any site that claims to be social. This is a basic tool to get opinion of visitors on topics and works as viral marketing too. However, sooner or later your visitors will question if your script is secure enough to avoid fake voting bots. So let&#8217;s cover couple ways how to avoid bots voting for your topics. </p>
<p>Unwanted votes fall into 2 main categories: intentional and unintentional. Unintentional ones might be search engines that try visiting your pages and similar. Intentional ones are made by people that want to screw voting statistics. Unintentional voters can be avoided using robots.txt exclusion, though one should not rely on it. You will not avoid intentional voters that way.</p>
<p>First, the vote should be a form element or javascript link. The reason is quite simple &#8211; a regular link is likely to be visited by search engines and it will screw up your voting results. Also, it is quite easy to add a link to any command line browser script. Although basic checking of browsers is a good thing, it will not work &#8211; the browser variable can be set freely in many of these scripts and it will protect from search engines and not malicious voting. Still, blocking most of the popular site grabbers in your .htaccess file might be a good idea.</p>
<p>Putting a limit on votes from the same IP has problems on its own as well. Although this makes voting more secure, it is quite unsuitable for local sites. There are cases when there are many users behind common firewall and share same IP address. This would make your site unusable for them. Also, it is quite easy to change one&#8217;s IP address with proxy while writing script. </p>
<p>Checking cookies is the most popular way of handling votes, though writing script handling them is quite easy as well. The most interesting variation of such voting script was implanting voting cookie from an image in the voting page and later checking for the value in the voting script. This prevented most basic form of voters that handle single page only. </p>
<p>Also, it is a good idea to check referrer of the vote (aka page the user came from). If the referrer is blank, you can be very sure that the user is either bot, or came to vote directly. </p>
<p>Captcha is quite good at preventing false votes as well, though it does not protect from manual multi-voting. The problem is that it ads complexity to the voting process so less people are ready to express their opinion. </p>
<p>An alternative for captcha is using serials in the voting forms. These serials are checked with the value stored either in cookie or db upon voting. Sadly, this will not protect from better voting script. </p>
<p>So, how to choose right method for you?</p>
<p>Here some suggestions: </p>
<ol>
<li>Decide how much secure your form has to be. What will force people wanting particular result ? In some cases you do not have to use protection against intentional voters.</li>
<li>Do not use captchas for simple votes &#8211; you will get less input on topic</li>
<li>Upon vote, log everything into db: Time, referer, browser, ip, cookie value. Later you can use that data to see if some of the data repeats too often.</li>
<li>It will not hurt to check server logs. Typical voting script will not bother to load CSS/images/JS. Look for queries from IP that does not load any images or scripts and just votes.</li>
<li>Look for spikes in the data gathered. </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/how-to-write-non-sucking-voting-script/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>KomodoEdit Review</title>
		<link>http://www.majauskas.com/komodo-edit-review</link>
		<comments>http://www.majauskas.com/komodo-edit-review#comments</comments>
		<pubDate>Tue, 29 Jul 2008 21:36:58 +0000</pubDate>
		<dc:creator>Giedrius</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[komodo edit]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php editor]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.majauskas.com/?p=61</guid>
		<description><![CDATA[I have to admit that Komodo Edit 4.4 is the editor I use the most for editing and developing. What I like is code collapsing/expanding, quite nice syntax help, also SSH2 support, which is a must for any editor. Additionally, it is free (there is a paid Komodo IDE version too). Overall, quite nice tool. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.majauskas.com%2Fkomodo-edit-review"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.majauskas.com%2Fkomodo-edit-review&amp;source=giedrius&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6b70a2205c1a0ba9dbc37392e42c745d" height="61" width="50" /><br />
			</a>
		</div>
<p>I have to admit that Komodo Edit 4.4 is the editor I use the most for editing and developing. What I like is code collapsing/expanding, quite nice syntax help, also SSH2 support, which is a must for any editor. Additionally, it is free (there is a paid Komodo IDE version too). Overall, quite nice tool.</p>
<p>However, there are couple of points where it could improve as well.</p>
<p>First, Komodo edit&#8217;s project management is far from satisfactory. It automatically adds files in the same directory as project file to project, which is not desirable behavior sometimes. Quite often project files are used for keeping shortcuts to important files in remote server only, so the &#8220;projects&#8221; are quite messed up. The more project you got, the more messy it looks <img src='http://www.majauskas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>What’s even worse, the files in project are handled by their name, and not by name and location like it should be. So, you can not add 2 files with same name to same project, even if locations are completely different. One co-worker even lost content of one file due to this &#8220;nice&#8221; Komodo edit&#8217;s feature.</p>
<p>The remote access to files needs a fine-tune too. In previous versions, reloading a project would change active remote dir to the one of last file loaded. Nowadays it does not change it, and it feels like a downgrade in capabilities &#8211; I have to browse more till I can edit the files required.</p>
<p>Overall veto: Komodo Edit is more geared towards local project development with some ocasional edits on remote server. Quite good tool if you are cheap <img src='http://www.majauskas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.majauskas.com/komodo-edit-review/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
