Is PHP a good first language?

May 1, 2008 – 3:47 pm Tags: ,

Sometimes I’ve seen people say PHP is a bad first language, because it teaches bad programming habits. But is this actually true at all? Often those who say that don’t really like PHP themselves either, many times because of equally untrue reasons.

I think PHP is a perfectly good first programming language – I would even go as far as say it’s possibly the ideal first language if you are interested in web development.

What makes a good first programming language?

When I began programming back in.. uh.. I think somewhere in the ’90s, I started with C. There weren’t really any other languages than C and Turbo Pascal that a young wannabe-programmer might have known of back then, at least where I grew up.

C is a lousy first language.

  • C has a lot of difficult to understand concepts like pointers
  • You have to write a lot code to do anything
  • Want something outside the console? Not going to happen any soon.

Because of the above reasons, C is not a very good language to begin your programming studies with.

But why?

If you aren’t really interested in programming, like I was, you will not get much incentive to continue. You get some console prompts – really boring stuff today. We can easily flip around those above three points and come up with…

A good first language should:

  • Not require complicated things to get going
  • Be powerful – provide high level functions to do things with less code
  • Be able to provide something concrete to show you your progress

So we can say that a good language should be simple to use, but powerful and have real functionality – ie. not a toy-language – and encourage the fresh developer to continue by easily letting them do something useful and cool!

PHP is nearly perfect

With the points made, I would say PHP is definitely a nearly perfect language for people looking to get into web development.

PHP is not a complex language. It’s quite easy to use and understand, but it still has the features of a “real” programming language like Object Oriented Programming. It can be an easy beginner’s language, but it also provides you room for learning new things.

PHP has a huge library of built in functions and classes that make almost all tasks very easy to do. Read the contents of a file? Sure – $myvar = file_get_contents(‘myfile.txt’); – Now, do it in C…

And thanks to the above points and the fact that you can embed PHP in HTML, it’s very easy to make something that you can feel proud of. Just throw together some HTML and PHP, host it and you can show everyone what cool stuff you’ve made.

And finally, PHP is a very popular language! If you learn PHP, you can be sure that you can find employment coding it.

Reasons to not choose PHP

Often people say that PHP makes it easy to write bad code, which makes it a bad first language.

What’s wrong with writing bad code, if you’ve just began your programmer’s career? Isn’t that what beginners do – and it’s perfectly fine.

Some other arguments include PHP’s poor decisions in the past, such as enabling magic quotes (which automatically escape post, get and cookie vars with backslashes, sometimes leading to confusion) and register globals (get, post, cookie and some other vars get automatically registered on the global scope) by default. These two are also often used as general attacks on PHP – which I really don’t understand. Sure, they aren’t exactly good things, but you can disable them.

Some also say that PHP’s builtin functions don’t really follow any conventions, which is not true at all. It may not follow a specific convention 100% strictly, but it does not make it a worse language as it’s more than enough similar for most parts.

Learn PHP!

I would encourage any new programmer to pick up PHP. It’s great, despite what people say about it.

Share this:
  1. 32 Responses to “Is PHP a good first language?”

  2. Yes, php is a good first programming language, i got started programming when i tried php, it was easy to start with, and you didn’t need alot of difficult theorys’ before you could make something.

    But it is hard to come from slam php starter programmer, to a well organised programmer. But again i think it is a good first language, since it is so easy, and it learns the person many objective programming aspects :)

    By Kasper A. Svendsen on May 1, 2008

  3. I think it does not really matter what language you start with, especially if you don’t have any “proper” education in programming, it is difficult to find out good practices and such.

    I’ve found a good way to learn good programming style and practices is to read books that talk about it. I’ve probably mentioned books such as Code Complete and The Pragmatic Programmer before – those two are really good ones and you can learn a lot from them in my opinion.

    By Jani Hartikainen on May 1, 2008

  4. I think that PHP is an excellent first language for a beginner for the reasons you’ve stated. I also think that if you get a very good PHP programmer to teach you how to use PHP, then you can avoid the nasty habits that PHP noobs usually pick up from cutting and pasting fragments off the web.

    That being said PHP is not without its problems. Its OOP implementation while vastly improved in PHP5 can still make running into a language with a solid OOP implementation a little hairy.

    Case in point, see this gotcha I ran into assuming stuff would work as it did in PHP

    If you’re using PHP, make sure you use PHP5 and then try to balance it out by programming in Ruby or Python. It will expand your mind in ways you won’t understand from just reading this.

    By austin_web_developer on May 1, 2008

  5. The answer depends on the goal of the learner. If the learner is motivated and wants to become a well rounded developer, they’re probably better of starting with an “academic” language like Scheme. If the learner has a short attention span and wants to see results quickly (which is probably the majority of people), then PHP is probably a great option.

    By Bradley Holt on May 1, 2008

  6. That gotcha could be avoided if you note that Ruby’s array is a class, instead of a type like PHP’s. Class instances in Ruby, like in PHP, seem to be copied as references based on that… Never done any Ruby programming really, so I won’t swear it’s correct.

    I have to agree on Python (and probably Ruby, too) – Python is a great language. Has its haters, again, though.


    Yep, that’s true. If the person is really interested in programming, they might be better to start with a language like C, Scheme or whatnot. If you’re still dabbling whether to get more into programming or not, then a more high-level and powerful language like PHP (or perhaps VB.NET, if you want to write desktop apps) is good in my opinion.

    By Jani Hartikainen on May 1, 2008

  7. Yes, it’s an OK first language as long as it’s also your last language.

    Otherwise you’ll learn a warped view of programming and too many bad habits, which you probably won’t even realize aren’t necessary when you start using a language that don’t enforce such things on you.

    By Greg M on May 2, 2008

  8. Gee, I must be a bad coder then. 😉
    If you have opinions, please add proper reasoning and not just random attempts at flaming.

    By Jani Hartikainen on May 2, 2008

  9. As someone who started off in Java and then found PHP a bit later, I have to say that PHP would have been a MUCH better language for me to learn first.
    Even if just to get your feet wet learning how web applications work.
    A newbie can take the script approach and learn these things and then grow into the OO approach and onto frameworks such as Code Igniter, Symfony, etc.
    With Java man, for me…it was trial by fire…and yes writing tons of bad…_very_ bad code. After I learned PHP I found that my Java code started getting cleaner because the barrier to entry on PHP was much lower and I grew more comfortable with regular programming concepts much quicker.
    As I’ve griped about MANY MANY times, “real” programmers think PHP is just a crap language and look down their noses at those who program in it, but I have YET to hear an actual reason “why” from any of them.
    I like to think to myself that its because they’ve no experience with it (outside of the scripting portion perhaps) and that since it doesn’t have 16 different layers, that its no good.
    Now I’m mainly PHP, Grails and some Java, with Java being my last choice of the three.

    By ryan on May 2, 2008

  10. PHP was the first language I really cut my teeth on. But at the same time, I was reading a lot about OO design and how to apply OO principles in PHP. This was the single best thing I really could have done. I have since worked with “real” languages like C#, and I can tell you right now — the language has relatively little to do with how good of a developer you are. I’ve seen some C#/ASP.NET code that makes the *worst* PHP code I’ve ever seen look glamorous. Focus on good programming concepts, and how to apply them in the language of your choice.

    By ncloud on May 2, 2008

  11. I think PHP is not only a choice as the first language to learn, but the best. Here’s why:

    1- You don’t have to know everything about PHP to make it work.
    2- It’s free
    3- There are free IDE’s ( &
    4- Large following, this is useful for questions (
    5- It can work with other languages & services very easily
    6- After you learn the basics you can start to learn OOP (Object-oriented programming)
    7- Great database support (MySQL, MSSQL & Postgresql)
    8- Can make desktop applications as well as server side applications
    9- Platform independent (
    10- Do I need say more, get developing :-)

    By Phill Pafford on May 2, 2008

  12. PHP is a great language to get started. It semi forces its users to write something web based, thus picking up a little html and css on the way. And providing quick, pleasing results.

    As opposed to an ugly console calculator in C.

    Any starting programmer will write ugly code, it’s a no brainer 😛 I don’t think there is an argument, that PHP promotes more bad coding than other languages.

    It’s a chicken and egg situation.

    PHP has more novice programmers than most other languages, hence more badly written code.

    By Nick Verlinde on May 4, 2008

  13. “Otherwise you’ll learn a warped view of programming and too many bad habits, which you probably won’t even realize aren’t necessary when you start using a language that don’t enforce such things on you.” — Jani Greg M

    I think any coder who can’t break out of habits is a bad programmer! Don’t blame the tools.

    It can be seen in the whole java Vs the dynamic languages (ruby,groovy) debate.

    most java programmers moving to these languages, at first write dread awful code, because they are not used to thinking in these new paradigms: closures, duck typing, …

    Perhaps, some of them never get it, and just stick with their language. But that’s not the fault of the language, just the person

    By Nick Verlinde on May 4, 2008

  14. Fix: Nick’s quotation is by Greg M, not me. 😉

    The situation with PHP is a bit similar to VB6 – A lot of people say VB6 is crap, that it’s not a real language etc., while it actually is a totally fine tool for creating windows apps and such. Today it may be a bit outdated by things like VB.NET, though.

    Oh, and thanks for the diggs 😀

    By Jani Hartikainen on May 4, 2008

  15. hum.. why not Python?

    I still like Pascal though. :-)

    By henry on May 6, 2008

  16. If you want to get results quickly on the web then go for PHP, if you want to put more effort into learning core/advanced concepts right away then go for Python or Ruby.

    By Henrik Sarvell on Jun 27, 2008

  17. Can any please tell me how to become web developer ? How to get started , i.e which languages i have to learn ? Please tell me in order.Thanks.

    By doll on Oct 6, 2008

  18. The very basics of modern website development:
    1: HTML
    2: CSS

    Then a bit more advanced stuff:
    3: A server-side language of your choice, such as PHP

    Not necessarily required, but things that are always good to know:
    4: A database server, such as MySQL, and the SQL language
    5: JavaScript for client-side scripting

    By Jani Hartikainen on Oct 6, 2008

  19. Thanks Jani Hartikainen .

    By doll on Oct 6, 2008

  20. i think php and c# are good choices for beginners. as a php developer you can look to frameworks like Kohana or Codeigniter to help write better code

    By UtechFx on Oct 7, 2008

  21. thought this is a good and relevant video to this discussion:

    By TurboC on Oct 7, 2008

  22. I personally think that PHP is a terrible language for starters.

    It does not help people think about programming itself; it’s syntaxis, being C-like, distracts and takes the beginners far in a land of curly braces and “where does this IF statement end?”, rather than being thinking about what the program should be doing.

    I believe it is good for mediocre, if not masoquist people, who care more about getting an email web script to work, rather than understanding the basic fundamentals of programming and making things work right. In my experience, when you do things right, it may take a tad longer, but in the future, you always save time.

    As a language it is very untidy, making applications crazy to maintain and disorganized as time goes by. The “extraordinary feature” of embedding it in HTML seems to me its biggest marketing tagline (which by the way will make the life of thousands of programmers miserable).

    The popularity of PHP seems driven by the fact that suits, like to see results, and they like to see them fast. Whether they are good results, “It doesn’t matter. We will fix it tomorrow…” (in other words, “don’t do it right, just do it!”, or “what is wrong with writting bad code, when everybody else writes it too?”). Perfect way to build a foundation for your programmer’s career…

    Its popularity keeps growing strong because people seem to think it is free, when in reality, PHP is released whith a PHP license, completely pushed and backed by Zend Technologies.

    I started programming in PHP and I regret every single bit of it. It doesn’t help you create good habits; it will for sure make you an average programmer (which I think EVERYBODY likes, and somehow bow to); it will make you waste time learning that there are million of functions, the most you will never use, and many which “you have to be very careful, because PHP4 doesn’t like it”; its object oriented seems like a spear gun mounted on the back of a pick-up truck -a la Mad Max-, and its naming convention concepts are worse than the BMW GINA; “let me think… was is latex_gina or gina-spandex?” (Subaru fans might get this one… then again, all programmers that drive Subarus most probably use Ruby).

    People seem to be really afraid of being different and trying something new, because “oh my god, what an odd guy you are!” mentality. Same thing happens to Java, even though, it is a slow dog in usability (I encourage you to try OpenOffice).

    If you are a beginner, I really suggest you learn something with a better designed language, not “more logic and sense buit into it, as it ‘grows up'”. I urge you starting with something like python. If you want to develop for the web, then learn Django, and save yourself headaches, and time.

    By KingCharles on Apr 1, 2009

  23. While I don’t agree with all you say KingCharles, I really like your metaphors =)

    By Jani Hartikainen on Apr 1, 2009

  24. I am learning PHP myself and posting what I learn to my blog. I think PHP is a very good language to learn for beginner’s and it’s very popular as well. So far I think PHP is quite fun to learn and because I want to really get into web design I thought I start with this language fisrt (excluding HTML)

    By Nathan on Apr 6, 2009

  25. PHP was my first language, although I’ve only scratched the surface of it, I do know enough to get by on.

    I recently started learning python .. There are some differences, mostly to do with types and syntax. I can already see where my assumptions about programming are being smashed to pieces by seeing how another language does things. Things I took for granted as “the way things are” are no longer true.

    I would say that it’s a good idea to get familiar with a few different languages before you lock onto one specific way of doing things. If I had learned python first and then PHP, I would (probably) be having the same sort of moments.

    In a few months when I get the hang of Python, I’m going to pick up C and then GO :-)

    By Susie Day on Jan 17, 2010

  26. I’m learning PHP at the moment well I’m pretty much finished what I’m gonna learn of it. I got to agree with the general view of comments made but my lecturer has got us to be very strict with PHP and we cannot be lazy and leave out stuff that PHP allows eg initial assignment. Because he wants us to be as disciplined as possible because we will be learning Java next year, so it is a good language to learn if you have someone whipping you to do it properly otherwise no it will give you bad habits.

    By David on Mar 7, 2010

  1. 7 Trackback(s)

  2. May 3, 2008: Bookmarks for May 2nd : Blog-Her
  3. May 3, 2008: Weekend Links - MooTools Fancy Upload, 60 Second Tech, jSize, CSS Pull Quotes, PHP First Language
  4. May 11, 2008: PHP is a good second programming language « Glorified Geek
  5. Oct 6, 2008: Nerdlife » PHP is a /great/ first language for a hacker
  6. Nov 6, 2008: PHP不是首選的Language | 亞特蘭提斯 .NET Atlantis
  7. Dec 11, 2008: When PHP Actually Is Your First Programming Language
  8. Sep 7, 2011: PHP 是否理想的第一語言? | 香港網頁開發網誌

Post a Comment

You can use some HTML (a, em, strong, etc.). If you want to post code, use <pre lang="PHP">code here</pre> (you can replace PHP with the language you are posting)