20 Ways to Save Kittens and Learn PHP
basix

20 Ways to Save Kittens and Learn PHP

Tutorial Details
  • Program: PHP
  • Difficulty: Beginner
  • Estimated Completion Time: 1 hour

Twice a month, we revisit some of our readers’ favorite posts from through out the history of Nettuts+. This tutorial was first published in January, 2011.

There’s an old adage – dating back to the 1700s – which, in English, says: “A kitten dies each time a PHP programmer doesn’t follow best practices.” Okay, not really; but just go with it!

Getting started in PHP can be a daunting experience. With that in mind, these 20 tips will teach you how to follow best practices, and save lives…kitty lives.


0. Program as Often as You Possibly Can

Programming often and with purpose will make the lessons you learn stick.

Did you study a foreign language in school? Studied all the parts of speech, learned the verbs and how to conjugate them, followed along as your teacher said common phrases?

How much of that language do you still speak?

If you’re answer is, “none,” I’m willing to bet it’s due to the fact that you never actually used the language — you only studied it. But if you can still hold up a conversation, it’s likely because you actually spent some time speaking that language outside of the learning environment. Perhaps you spent a year abroad, or worked a job where a second language was necessary?

Whatever the reason, you retained it because you used it in real-life situations and put it into a personal context that is much easier to recall later.

PHP is a foreign language, just like Spanish or French. In order to become comfortable with it, you need to use it outside of the classroom setting. Tutorials and sample projects are great for teaching the fundamentals, but unless you’re applying those concepts to your own projects, it will be much more difficult to apply those fundamentals in context and burn them into your memory.

So, don’t worry that you “don’t know enough” to build a project. When you choose your project, you have a valid reason to research and implement a concept. Programming often and with purpose will make the lessons you learn stick.


1. Get Familiar with the PHP Manual

Every list of tips for beginners has this tip, and for good reason.

Learning to navigate the PHP documentation is the single most useful thing you can do for yourself as a programmer.

If you look in my browser history at the sites I most often visit, the PHP manual will be right at the top. I don’t suspect that will change for as long as PHP remains my programming language of choice.

At first, the manual does look rather daunting — it doesn’t seem to be particularly easy to browse, and the navigation can be a bit awkward at times. However, you’ll get the hang of it quickly.

Perhaps the best thing to know about the PHP manual is that most functions can be looked up using the pattern http://php.net/function-name in your address bar. For example, to look up the strpos() function, use http://php.net/strpos, and for array_key_exists(), use http://php.net/array-key-exists. (NOTE: pay attention to the omission of parentheses and the substitution of hyphens (-) for the underscore (_) in the address.)

1a. Read the Comments!

It's easy to overlook the comments, but do yourself a favor and have a look through them. If you're getting an unexpected result from a function, chances are someone has spotted it and explained it in the comments.

You can also pick up a plethora of great tips and ideas from the developer community by reading through comments.


2. Take Advantage of the Huge Online PHP Community

In addition to the PHP manual, there are wonderful developer communities all over the internet. Some of my personal favorites include StackOverflow.com and the W3Schools.com forum.

Additionally, Twitter is a surprisingly excellent place to post PHP questions. If you tag a tweet with #PHP, it's likely someone in the community will spot it and lend a hand.

A Note About Twitter: Of course, anything that's useful will inevitably be overrun with spammers and those sorry individuals who deeply misunderstood the purpose of social media. If you're going to use Twitter as a support network, you'll probably want to routinely block or hide the accounts which spew job postings or retweet everything that mentions PHP.

Just remember: as you get better, please try to pay it forward. The development community needs everyone to pitch in, and it won't be long before you'll have the ability to answer questions for other beginners. Don't turn a deaf ear.


3. Don't Put Off Best Practices for Later

As you're learning, you're going to hear a lot about "best practices" in programming; stuff like prepared statements and PEAR coding standards.

Do not put off learning this stuff because it seems hard.

If something is a best practice, it's not because we (meaning other PHP developers) got together and said, "How can we make life harder for the noobs?"

Best practices exist to keep your scripts secure, fast, and manageable. Learn them as early as you can. In fact, don't even bother learning the wrong way.

It takes just about the exact same amount of learning to figure out mysql_query() as it does to learn PDO or MySQLi. So if you start with your choice of the latter two, you're starting with a strong foundation in database interaction and, really, you've put in less overall effort.

Be sure to browse Nettuts+ for a variety of tutorials on PHP best practices, including prepared statement usage.


4. Don't Put Off Best Practices for Later!

I just wanted to make sure you saw this.

Seriously, folks. Don't take shortcuts. Every time you violate best practices because the right way seems "too hard," BP dips a kitten in crude oil.

So if you won't do it for yourself, your projects, your peers, or the advancement of the community at large, at least consider the kittens.


5. Make Code Self-Documenting

If you need to squeeze characters off your variable names to shave .2ms off your script’s execution time, there’s likely a whole different problem going on.

It's tempting, early on, to be "clever" with your variable and function names. Maybe you read an article about performance, or saw a code snippet that accomplished a ton of work in two lines of code. Maybe you want to create your own "signature style" of coding. Maybe you just heard that I hate it and you wanted to piss me off.

Whatever your temptation, resist it at all costs.

Consider the following snippet of code:

<?php

 $a = b('jason.lengstorf@copterlabs.com');

 $c = explode('@', $a);

 $d = $c[1];

 echo 'The email address ', $a, ' belongs to the domain ', $d, '.';

 function b($e) { return htmlentities($e, ENT_QUOTES); }

?>

Does that make any sense to you?

Of course, you can figure out what it does, but why force anyone trying to work in your code to spend the extra 1-5 minutes scratching his head, trying to remember what $c is storing.

So let's take that code and make it self-documenting:

<?php

 $email = sanitize_string('jason.lengstorf@copterlabs.com');

 $email_pieces = explode('@', $email);

 $domain = $email_pieces[1];

 echo 'The email address ', $email, ' belongs to the domain ', $domain, '.';

 function sanitize_string($string) { return htmlentities($string, ENT_QUOTES); }

?>

There. Much better. Now, just by glancing at the code, you can get the general idea of what's going on. No head-scratching, no muttered curses, and most importantly, no real difference.

Sure, you save a few bytes with short variable names. But, honestly, if you need to squeeze characters off your variable names to shave .2ms off your script's execution time, there's likely a whole different problem going on.


6. Add a Comment to Anything You Had to Think About

Comments are the sign of a competent programmer.

Comments are not the sign of a novice. In fact, as I see more and more code that's not mine, I'm starting to think that comments are the sign of a competent programmer, as they seem to be the only ones doing it.

If your code is self-documenting, you won't require too many comments. However, no matter how clear your variable and function names are, you'll always have spots where the action taken simply isn't that obvious.

When that happens, slap a comment in there. "Future You" will give "Present You" a high five when the time comes to update the script.

As a rule of thumb, if you had to stop and think for a few seconds about what needed to happen to make the script work properly, it's probably a good spot for a quick note.

Consider the following:

 
$pieces = explode('.', $image_name); 
$extension = array_pop($pieces);

What does that do? Did you have to stop and think about it? Do you still not know for sure what's stored in $extension?

Look at that snippet again, but with one quick comment:

 
// Get the extension off the image filename
$pieces = explode('.', $image_name); $extension = array_pop($pieces);

Now, even if you don't know how or why that code works, you at least know that $extension refers specifically to an image extension. If that saves "Future You" or another developer five seconds of processing the script's intent, it was well worth your ten seconds of effort to add the comment in the first place.

As with most things, moderation is key. Too few comments and you risk leaving the next developer (or Future You) puzzled by a code snippet, which can even lead to accidental breaking of code because the solution, without explanation, might look silly or superfluous. Too many and it becomes too difficult to scan through your code, which is equally frustrating.

Moderation is key.


7. Learn Docblock and Use It

If I could be sure every developer in the world would do one thing with absolute consistency, I think it would be the use of the Docblock commenting standard.

I have a few reasons for my strong support of Docblock:

  1. It requires one to think about the what and why for each file, function, method, and so on.
  2. It gives a clear description of the expected types for parameters and return values in functions/methods
  3. It provides a quick description of what the code does
  4. When coupled with one of the many IDEs that support Docblock, it creates code hinting (which allows you to see a description and expected parameters/return values for the method or function you're using)

This tip does border on the upper level of beginner, but I group this under "best practices to be learned as quickly as possible." Feel free to skip it, but before you do, think about the kittens.

Docblock shows its versatility best when used to document a class:

/** 
 * A simple class to get the sum or difference of $_foo and a value 
 * 
 * @author Jason Lengstorf <jason.lengstorf@copterlabs.com> 
 * @copyright 2011 Copter Labs 
 * @license http://www.opensource.org/licenses/mit-license.html 
*/ 

class CopterLabs_Test 
{

 /** 
  * The value to use in addition and subtraction 
  * @var int 
 */ 
 private $_foo = 0;

 /** 
  * Adds a value to $_foo and returns the sum * 
  * @param int $add_me The value to add to $_foo 
  * @return int The sum of $_foo and $add_me 
*/ 
public function add_to_foo( $add_me=0 ) 
{ 
  return $this->_foo += $add_me; 
}

 /** 
  * Subtracts a value from $_foo and returns the difference 
  * @param int $subtract_me The value to subtract from $_foo 
  * @return int The difference of $_foo and $subtract_me 
*/ 
public function subtract_from_foo( $subtract_me=0 ) 
{ 
  return $this->_foo -= $subtract_me; 
}

}

At first it might look overwhelming, but the benefits are very much worth taking the time to familiarize yourself with the syntax.

The above Docblock, when used in Netbeans, will generate the following code hint:

Code hinting in Netbeans

8. Don't Be Too Hardcore to Use an IDE

If you don't already know the type, you will soon: the developers who think real programmers don't use IDEs.

Now, look: if you want to impress people, learn to juggle. Refusing to use anything but Emacs in the command line to write scripts will not get you chicks or grant you instant hacker status; it will, however, hang a sign on your forehead warning your coworkers that you are, in fact, That Guy.

Don't be That Guy.

There is nothing wrong with using software to give you on-the-fly syntax highlighting, error-checking, and code hints.

How in-depth your IDE goes is entirely up to you. Personally, I really like Netbeans. I've heard tons of praise for Coda for Mac (though it's not really an IDE), and I previously used Eclipse before moving to Netbeans.

Whatever IDE you choose, you'll see your coding speed increase and your facepalm-worthy bugs decrease. Further, as you expand your code library, you'll have code hinting for all of your custom software. (Because you're using Docblock, right? Right?!)

Don't think IDEs are uncool -- no matter what "That Guy" tries to tell you.


9. Group Common Code Into Functions

If you see an action repeated, it's time to strongly consider moving that code into a function.

When you first start programming, it's easy to start at the top of the page and work down, adding each piece of code right where it's needed.

However, when you code this way, you'll begin to notice that certain pieces of code are appearing over and over again. This is a minefield when it comes to maintenance and upgrades, because you have to hunt through each file for every occurrence of that action to change its functionality.

If you see an action repeated, even if it's only twice, it's time to strongly consider moving that code into a function.

Consider the following for example:

$unclean1 = '<a href="javascript:alert(\'Holy Crap!\');">Click Me!</a>';

$detagged1 = strip_tags($unclean1); 
$deslashed1 = stripslashes($detagged1); 
$clean1 = htmlentities($deslashed1, ENT_QUOTES, 'UTF-8');

$unclean2 = "Let's call Björn!";

$detagged2 = strip_tags($unclean2); 
$deslashed2 = stripslashes($detagged2); 
$clean2 = htmlentities($deslashed2, ENT_QUOTES, 'UTF-8');

echo $clean1, "<br />", $clean2;

As you can see, both of those strings required a few steps before they could be considered safe to use. However, you'll also notice that those same steps could be considered necessary for every bit of information that is passed to the script.

This is an instance where using a function instead is far more desirable:

$unclean1 = '<a href="javascript:alert(\'Holy Crap!\');">Click Me!</a>'; $unclean2 = "Let's call Björn!";

$clean1 = sanitize_input($unclean1); 
$clean2 = sanitize_input($unclean2);

echo $clean1, "<br />", $clean2;

function sanitize_input( $input ) 
{ 
  $detagged = strip_tags($input); 
  $deslashed = stripslashes($detagged); 
  return htmlentities($deslashed, ENT_QUOTES, 'UTF-8'); 
}

By wrapping the common code in a function, it's a bit easier to see what's going on, and it's much easier to edit the steps you want to take when sanitizing your input.


10. Group Related Functions Into Classes

Getting a handle on OOP is another one of those things that I file under "best practices to learn as quickly as possible."

If you have a handful of functions that all deal with database actions, you can save yourself a lot of time and effort by grouping them into classes.

Learning object-oriented programming is definitely outside the scope of this list, but I felt it was definitely worth mentioning in this beginners' list.


11. Use Constants, Not Globals

PHP allows you to define your own constants with the function define().

When I first started programming on larger projects, I found myself using global variables more often than seemed necessary or reasonable. Admitting you have a problem is the first step.

I was storing things like application-wide data (such as the site's name or the maximum image width) and database credentials in variables, and I found myself required to use the $GLOBALS superglobal to access this information.

Then I realized PHP allows you to define your own constants with the function define().

A constant is a great way to store information like the aforementioned app-wide data and database info. An additional bonus is that it can't be modified, so you can't accidentally overwrite your database password somewhere later in the script.

As a matter of best practices, the use of globals is generally discouraged to begin with, so the use of constants is preferred anyways. Review the following code for an example and see for yourself:

<?php

define('FOO', 'constant value');

$bar = 'global value';

echo baz();

function baz() 
{ 
   $constant = ' Constant: ' . FOO; 
   $global = 'Global: ' . $GLOBALS['bar'];

   return $constant . "<br />\n" . $global; 
}

?>

12. Don't Be Afraid to Use Includes

Often, as you're building larger products, it will make a lot of sense to break it apart into smaller chunks, or include files.

A generally accepted way to look at includes is to put any bit of code that will be used in multiple scripts into an include file (such as your database connection details, the header and footer data that is common across the whole site, utility functions like your input sanitization actions, etc.) so it can be pulled in by the file that needs it, rather than being copy-pasted.

For example, on a site with multiple pages, a standard template may emerge that looks something like this:

<?php

// Application-wide data and database connection 
require_once 'constants.inc.php'; 
require_once 'database.inc.php';

// Utility functions 
require_once 'utilities.inc.php';

// Header markup 
require_once 'header.inc.php';

/* * Page-specific processing goes here */

// Footer markup 
require_once 'footer.inc.php';

?>

13. Don't Obsess Over Performance

This is a point of near-paralysis for some developers, and it's really too bad; there is a blurry line between writing efficient code and wasting time trying to squeeze an extra 5ms out of a script's execution.

Definitely read a few performance articles and learn some of the major pitfalls that can drag your scripts to a slow crawl, but don't waste extra time refactoring your code to change double quotes to single quotes because you found out it was a tiny fraction faster.

Use your head, avoid the big problems, and keep your ears open, in case a tip you've never heard comes along to speed up your code, but don't make it a race.

No one can tell the difference between a 25ms page load and a 40ms page load. Make sure it's not 700ms and move on to more important things.


14. Avoid Marrying HTML to Your Scripts

This can be tricky, but do your best to avoid tangling up your HTML markup in your PHP. It's nearly impossible to get away from it completely, but try to make sure that you don't include any non-essential HTML markup in your code.

Consider the following:

echo '<div class="example-div"><p>This is some test content.</p></div>';

Was it necessary for that code to wrap the paragraph tag in a div? Could it have been modified to only include the paragraph tag that holds the text? Have a look at an alternative solution:

<div class="example-div"> 
   <?php echo '<p>This is some test content.</p>'; ?>
</div>

Note: This example is grossly oversimplified. Generating HTML with PHP is usually more of an issue when dealing with a complex function or method that organizes a dataset. The point I'm trying to make is that it can sometimes be tempting to include more markup than is necessary in the output.

In most cases you can keep the HTML outside the PHP, which makes things easier to read and, usually, easier to work with as well.


15. Try to Use at Least One Unfamiliar Concept in Every Project

Push yourself outside your comfort zone.

You're never going to learn if you keep doing the same old thing. Try out a concept that you're not quite comfortable with on every project you possibly can.

Don't be over-ambitious, but definitely push yourself outside your comfort zone. It gives you a challenge, saves you from getting bored doing the same old thing over and over again, and forces you to progress as a developer.

Look at the project, find all the bits that you know well (or at least well enough), and then pick an area you'd like to understand. Sign up for it. Then do it.


16. Don't Be Too Proud to Change

You will be wrong. Frequently. But that's not a bad thing.

As you improve, you'll find newer, better solutions to problems that you've faced in the past. Don't feel stupid; you're learning.

But it's extremely important that you don't become attached to the code you write. Don't think your way is better just because it's your way. If you happen across a great solution that makes yours look like a Band-Aid on a bullet wound, use it! Pay attention to what's different and what you did that could have been better. File that away under, "Things I've Learned."

Never allow yourself to believe that an inelegant solution is acceptable because it's yours. That's hubris (which, if you're not aware, doesn't generally result in happy fun times).


17. Validate

If you're a web programmer, start becoming familiar with input validation as soon as possible.

Keep in mind: validation is quite different from sanitization.

Input validation is the practice of making sure data matches the format you've requested, like checking an email field for a valid email address or ensuring that a submitted username is 8-20 alphanumeric characters.

It can be tedious and a pain in the ass, but making sure that only valid data makes it through your processing scripts will enhance the user experience and avoid a lot of bugs in the scripts that have to use the data later on.


18. Whitelists Instead of Blacklists

If you're not on top of your blacklist, vulnerabilities appear.

In plenty of situations, you'll want to block or get rid of certain tags, words, email addresses, or other various bits of data.

A common solution is to use a blacklist: a collection of the tags, terms, etc. that aren't allowed.

This poses a problem, however; you have to be more clever than the person trying to do something naughty. For instance, in the case of disabling JavaScript in posts, you might blacklist the onclick attribute, as well as most of the event attributes, but what if you forget one? What if a new one is added to the spec sometime in the future?

If you're not on top of your blacklist, vulnerabilities appear.

However, to save headache later, use a whitelist whenever possible. A whitelist is the opposite of a blacklist: a collection of allowed tags, terms, etc.

For instance, in the strip_tags() function, you can provide a whitelist to specify which tags are allowed in strings:

strip_tags($string, '<em><strong><tt>');

Now your problem is most likely going to be that you can actually do less than you wanted, but that's far safer and usually less of an emergency to handle.

You can't get away with it in every situation, but saying what is allowed vs. what isn't will provide you with more confidence and control over your scripts.


19. Learn to Count Like a Computer

Are you looking for tip #20? Remember that in nearly all cases, counts in PHP start at 0, so this is actually the 20th tip. You'll find this to be the case in most languages; don't let this one trip you up!


Summary

If you're a beginner, the tips covered above will help you take great strides toward good habits and best practices. Don't get overwhelmed if all of this is news to you; take things one step at a time (see tip #15).

Tags: basix
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://matt-bridges.com/ Matt Bridges

    Wow, I save kittens on a regular basis and I didn’t even know it. I admit I have never been particularly attracted to IDEs, but I am reconsidering. I have used NetBeans, Aptana, Eclipse, and Dreamweaver in the past, but right now, Dreamweaver is quickly accessible until I download Netbeans (my personal favorite thus far) later on.

    Great article!

  • http://www.think360studio.com/ Eva

    Great PHP tips Jason..thank u :)

  • http://ninepartnership.com Jacob

    This is an instant bookmark. I tend to look at PHP as a whole and get overwhelmed… looking at these tips as their own individual “lessons” is a big help! Thanks.

  • http://www.weareprimate.co.uk We Are Primate

    Great article for people getting stuck into PHP for the first time or coming to it from another language. And I can’t praise point #8 enough! The amount of people I’ve seen who insist on coding in Notepad is ridiculous! I couldn’t live without Aptana Studio and it’s code insights, inter-project linking, shortcuts, FTP access etc. It makes working on large scale systems so much easier.

  • Larry

    The “prepared statements” link for tip #3 is incorrect. Great article otherwise, thanks!

  • http://nfxdesign.com Laurence

    These are some really good tips. This coming from a PHP beginner.

    L

  • Denzyl

    Thanks for a great list.

    I’m just getting into PHP by reading anything I can find. But something I keep running into is item #0. I don’t have a clue on what projects I can start on my own. Books usually lead up to building a CMS but as a beginner I don’t see that as being helpful – I could be wrong. I have projects I want to make but they’re complicated and I need some stepping stones.

    Another great article would be a list of different projects that details the skills needed to complete each project. The the next project would then use the cumulative skills to complete it – so on and so forth.

    Thanks again Jason.

    • http://www.copterlabs.com/ Jason Lengstorf
      Author

      One of the benefits to doing a CMS project is that it teaches you all of the major pillars of web development: building front-ends, back-ends, database interaction, input sanitization/validation, and common data manipulation used for the web.

      You may never use your CMS, but I’ll guarantee that you’ll use the skills you pick up in building it.

      Good luck!

    • http://charleyramm.co.uk Charley

      I had a breakthrough when I started learning some basic C programming. The syntax is very similar and the exercises in Practical C Programming (oreilly) are more suited to learning programming principles than many web-based examples.

      For example, exercise 7-2: Write a program to perform date arithmetic such as how many dats there are between 6/6/90 and 4/3/92. Include a specification and a code design.

      Without using ready-made date libraries I wrote a small program that could do this task, and was intelligent about leap-years and how many days are in each month. I am very proud of it and I think I learned a lot too.

    • frostymarvelous

      Personally I have never built a cms, but like Jason said, it teaches you all you need to know.
      I actually learnt from an online article (I love the community and I do give back esp on stackoverflow) and it used a forum as the teaching example.
      I lost the url but I think its the best beginner’s guide out there. I did use my forum and made it into a forum builder.
      Though you might not use the cms, I implore you to follow the tutorial. You’ll be thankful for it.

  • http://www.code-pal.com Sumeet Chawla

    Nice article…Loved the way you proved point 3 and explained that counting starts from 0 :)

  • JJ

    Storing site configuration and other information in constants? Why don’t you create an associative array with the data and put it within the local scope using global? Cleaner, easier, faster and much better than lot’s of ugly constants.

    $config = array(
    ‘server’ => ‘localhost’,
    ‘username’ => ‘root’,
    ‘password’ => ’123456′
    );

    And, anytime, inside a function or class method:

    function blah() {
    global $config;

    echo $config['server'];
    }

    • Chibby

      Like the article explains, it’s neither cleaner nor much better than using constants.
      Constants can not be overwritten.
      Globals are evil, as they are accessible in the entire scope of the code (and can thus be manipulated _everywhere_).

      The way I usually work is to set up a database connection by using a class specifically designed for handling all database operations, including setting up the connection to the server and database.
      Just instance the class and pass the values:
      $database = new Database( “user”, “pass”, “host”, “database” );

      Another way is to have configuration files that have this information (in my case at work a proprietary syntax is used) which are then read by the framework which sets things up as you need them.
      (I for instance need not worry about my database connections anymore. As soon as I query the database, and I have my credentials in such a config file, the db class makes the connection for me, and also closes the connection in the class’ __destruct() method.)

  • http://www.europeholidaytips.co.uk Erwin

    Hehe, I think a lot of kittens died because of my shortcuts, def something I need to work on, posts like this give me motivation for that.

  • http://jameserie.info James

    I’m lack of Code Self-Documenting. Anyway thanks for the tips.

  • Jeetal

    Thanks Jason! These are great lessons and very well written.

  • znet

    How about “A kitten dies each time a programmer uses PHP.”?
    Seriously, PHP is a language that seems to have no concepts. How can you add a “goto” statement to a language in 2009?!?! (“goto” is available in PHP since 5.3, which was originally released in June 2009).
    I really want to know what went on in the guy’s brain when he added this.

    PHP still has no array dereferencing, meaning if a function returns an array, you cannot directly access an element of that array like “$yay = foo()[0];” SRSLY, WTF?

    And I really don’t want to get startet with some other “interesting features” of PHP… Have fun in your little PHP world ;)

    (Don’t get me wrong. I startet out with PHP, too. That was two years ago. And I am sooooo glad I got away from it!)

    • http://ajbapps.wordpress.com Alan

      *cough* Troll *cough*

    • daBayrus

      and how much Facebook is worth now compared to your non-PHP web apps? lol..

      • http://foobar.com Foobar

        Ohhhhh snap!

    • frostymarvelous

      Until people understand the history of php, we will continue to have silly arguments like these.
      The language was built as a templating engine for ****. Its only been developed further due to its popularity. Personal Homepage, now Hypertext preprocessor. That should simply tell you what it is.

      So of you don’t like what it is, its good you left. Some of us use it for what it was meant for.

  • http://ajbapps.wordpress.com Alan

    I would add use a framework to the list… it will help your build on best practices will exposing you to a great structure to develop on top of.

  • http://www.hosting-tr.net Burak

    Congratulations. Very impressive article.

  • http://www.think360studio.com/ Think360 Studio – Web Design Company

    Nice tip list!

    Thank you for this nice article.

  • Marty

    Hi, do I need to know to how to work with Photoshop if I want to be web developer? I like programming but I am not good at design and graphics (I don´t have ideas and sense for colors). Can I find job about only PHP a JS development without knowledge of Photoshop or only with PS basics?

    Sorry about this “offtopic” but I wanted to know it. And sorry about my english, it isn´t my native language.

    • http://www.visual-blade.com Daquan Wright

      No, not if your a *insert language* developer. What you’re expected to know are good programming habits and experience building applications in that language. If you want a job in PHP/JS, then that’s what you need to know. Photoshop or any other graphics application has nothing to do with programming.

      Investing or getting a good software to write code in, however, is very important as it makes you more product. Also, blog on your language of choice because you meet developers who also know the language.

      As for IDEs/Editors, I use Notepad++, E – text editor, and Aptana Studio. As long as you know what’s going on, using tools to automate processes is quite beneficial.

      Good article.

  • http://themeplay.com/ kalis

    super nice article

  • http://www.abhinavsood.com Abhinav Sood
  • Miguel

    I did not know you could re-feed Envato posts.

    http://gigaspartan.com/2011/02/01/save-the-kittens-php-must-follows/

  • http://www.prasadgupte.com Prasad

    Very nice, thanks! I particularly liked the last one (not that I was looking for #20)

  • Jake

    Your link to Eclipse has a ; after http instead of :

  • http://dev10.nl Wim

    Nice list of points to consider, except #10.

    OOP isn’t about putting functions that have to do with each other in a class, it’s about Objects and how they deal with each other. Polymorphism and stuff like that. That has nothing to do with similar functions.

    • frostymarvelous

      Actually it does. Wikipedia states it as one of the levels of coupling.

  • Guillermo

    Wow, Very informative and your style of writing makes it fun to read. Thank you and please continue to help us save more kitten, :)

  • http://www.w3resource.com Ritwik

    I support the point no 8. Particularly when you are new to PHP, it should code using a text editor only.

    • EllisGL

      If you are new to PHP and are exploring, IDE’s (such as Netbeans) can really help figure out things. I started out using notepad back in 99, found PHPEdit, then ditched it for NotePad++ then found Netbeans.

  • http://menian-lee.eu/ Kitten Slayer

    Thanks for the 20 tips. I’ll try to put them in use as soon and as much as I can (*:

  • Wallysson

    Hey man, nice tut!!!
    Especially the tip 20!

    Thanks!

  • http://www.ejsexton.com/ E.J. Sexton

    I love and completely agree with tip #8. I recently had a co-worker who was new to PHP and refused to use an IDE for the first couple weeks of his employment. Instead, he installed EMACS and VI on his Windows XP workstation. He changed his tune a couple of weeks later and started using NetBeans—some of the time, at least. He also used words like “1337″ and “haxx0r” excessively in IM conversations, but I won’t go into that…

    • EllisGL

      Yeah I know a few that refuse to use anything other than VIM. Of course they put in a random number of empty lines between things and don’t have standard of parsing.

  • http://tareq08.wordpress.com tareq

    nice article. its really helpful :)

  • http://www.acknowledgework.com Carlos

    Great article, definitely a good reminder on how to get better and some new tips to use.

  • Catalysta

    Good article – thanks for the tips.

  • http://www.mlabs.info Samuel Marian

    Great tutorial. The title is a little funny! :)

  • http://www.dropw.com Mosarrof

    Nice Article, Specially helpful for me :)

  • http://www.serprisedesign.co.uk Kevin

    Really useful advice, I’ve been looking to learn PHP but never really get around to it.

  • Oscar

    Great post man, a must see

  • Mandeep

    Thank you so much. This greatly helps out a great ordeal to a beginner like me. :)

  • Srtz

    Thanks a lot!!!

  • Kazper

    Great post Jason.. Thank you :)

  • http://www.idealhomesportugal.com David

    Great tips, got to keep saving those kittens!

  • http://www.ucertify.com avinash

    I have saved to many kittens!!

  • Mahavir

    Very Good to understand PHP awareness !!

    ” BEst LuCk “

  • http://reygcalantaol.com reyBorn

    I am a web developer and I am using php. I mostly used functions but not so much on classes. I am not much acquainted with classes but I want to learn on it. I hope I could find a tutorial for it.

  • http://www.lk-webdesigns.co.uk LKenneth

    Excellent Tips here!

  • http://www.dkaggarwalwordpress.com Deepak

    Excellent article – thanks for the tips.

  • David

    A lot of these I learned the hard way or from a friend, but it’s a wonderful collection of tips.

    Thank you!

    • David

      ps – I read ALL of OOP article in the middle of this and learned a lot from it… then I resumed this one and bookmarked as necessary. Sweet deal.

  • frostymarvelous

    Three years on and I still read every best practices article I find. Guess I save lots of kittens. How I know this is a great article, I relate to every single point.

    I liked dreamweaver with code hinting especially core functions, but I prefer notepad++. Maybe because it is portable and I move around a lot or maybe cos I learnt to code In it.

    I find the php community is great and the manual is the best thus far. Super. Attach anything to php in google and php.net should be in the first three usually with a solution in the comments.

    I always go out of my comfort zone and most often than not, start a new project when I learn a new thing. I did that with the Singleton pattern and registry patterns.

    Nice writing style. Funny and straight to the point. Wondered why you started at 0 though lol.

    And oh, Don’t put off the good practices until later.

  • http://www.gurushala.net shashank chinchli

    great blog dude !
    M going to start learning PHP soon so this post was like motivating and great for self guiding!
    thanks a lot.

  • vijay

    I am a newbie… Thanks for the tips… I will start using these from now on…

  • Zainul Abedin

    I don’t like to be too harsh. But constants are constants and variables are variables. There is a big problem if you don’t know which one is which.
    Good or bad habit die hard!
    Think of the cases where there are embedded systems, programs and data are stored partly in volatile memory and partly in write-once memory, then there are data-driven programs, etc. etc.
    To cater for different applications it is better to be ready and practice from now!

  • Tom

    Thanks for this, Great Rea for a new Developer