When PHP Actually Is Your First Programming Language

I have read a few articles about how PHP is a perfectly good first language and how it should never be a first. These articles are interesting because my first programming language was PHP and I have been using it extensively since 2004.

One thing is true: it’s really easy to get started with PHP. My first real job was creating a system to log phone call metadata from a PBX. I was able to get a working version up quickly because 90% of it was in PHP. There’s a function for nearly everything, and if there isn’t, you’ll find sample code online quickly. I had the project done in a month with very little prior experience. However, because it was so easy, it was horrible. Procedural, PHP inline with HTML, calls directly to mysql library functions, really bad logic.

When I was brought on to develop on their flagship web application, my coding practices improved from exposure to a better codebase. The biggest improvement was when I started working with PHP code developed by a new coworker that I would later learn was heavily influenced by Java. I went from looking at objects as namespaces to a representation of something. I learned to separate logic from presentation. I started to think about code more logically. I was baffled at problems caused by PHP’s lax nature (such as when (0 == 'hey') is true). However, I had knowledgeable coworkers to explain these problems when the language wouldn’t.

The best thing about PHP is that it takes away the need to manage “stuff” and let’s you get started right away. For me, I was able to more quickly grasp object oriented programming because PHP was more forgiving. This later helped me embrace objects in JavaScript, understand polymorphism, and become a better web developer.

That’s also why it’s so awful. If it weren’t for my exposure to good PHP code influenced by proper programming practices, I would have remained a contributor to the vast amount of bad PHP code out there. The unfortunate problem is that most new developers who use PHP stay in that place, because their stuff works. For most jobs, that will suffice. It’s only when they move to other languages that the frustration begins.

Making PHP my first language made it harder to grasp pointers, strong types, and memory management in other languages. It initially made it more difficult to use OOP properly. However, if I didn’t make PHP my first language, I may have been so intimidated by the “stuff” that I may have given up.

Whatever you choose to learn as your first language, the key is to learn from great code. You will make mistakes and your language, framework, or mentor should be there to guide you. If you don’t, you’re only going to become frustrated and confused later.

Update: There’s a good discussion about this article on Hacker News.

My first languages were actually Applesoft BASIC followed by VB6, but nothing serious came out of my experimentations with them except for a brief stint working on ignitionServer.

Published by Reid Burke

Hi, I'm @reid. I work on developer tools at Yahoo. I serve at Awakening Church with a focus on technology. I also enjoy riding motorcycles.

15 replies on “When PHP Actually Is Your First Programming Language”

  1. Heh. My first programming language was also PHP. I’d say it doesn’t matter what programming language you first learn so long as you at least try a few other languages. I think getting the widest range of languages (e.g. Python, x86 assembler, Lisp, and Prolog) helped me understand how to make the most from the languages where you can (but don’t have to) write bad code.

    Anyways, if the programming community didn’t PHP developers, who would they pick on? Java?

  2. Great article.

    PHP was also my first “proper” language — the first one I did anything substantial in. And even though I subsequently learned Java and other “real” languages, I don’t see it as being a bad language. It’s a language that can be used badly, but so can any language.

    As for the obsession amongst other programmers with pointers and memory management, I say fuck those guys. The best automated garbage collection is now provably more efficient than doing it yourself, and saying somebody is a crappy PHP programmer because they haven’t bothered to learn about pointers is like saying somebody’s a crappy C programmer because they don’t know assembler instructions. The reason we invented higher level languages is because our computers became better than us at doing those things, so we could stop bothering.

  3. php is a decent language for teaching OO design and works great for certain domains, but there’s enough ambiguity and laxness in the language to make it difficult to learn in a non formal environment. if you subscribe to top down learning methodologies, than php works as a first programming language. imo, c++ works best as it gives newbies an opportunity to learn more about lower level concepts such as memory management and since it’s a compiled language, you learn assembly for free : D

    full disclosure: my first programming language was vba/vb3 followed by BASIC on my TI-80. c++ and php came later 🙁

  4. This is why I’m so happy the PHP community has been moving forward into the Framework movement. Since now every new article is “how to do X in Y framework” newbies in the PHP world can’t help but hear about frameworks and will get exposed to good code early.

    I personally believe new programmers should start with lower level languages. I technically started with C, did a stint on VB, then jumped back to C/C++.

  5. PHP has a syntax that is very similar to Perl, but Perl has a huge community and CPAN – a giant archive of already written code. If you like PHP you may want to look into Perl and some of the tools it offers – it might not be a hard transition to Perl and you’ll get some extra tools in your toolbox.

  6. Can any one 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.

  7. Christ, I wish I had knowledgable co-workers, even just once, it would be nice to see how it feels. 😛

  8. Although I dabbled with VB6 for a few years, it was never serious, and PHP was also my first language. I like it, I enjoy my job (PHP developer) and I can ignore the many foibles of the language. That said, I am very much aware that I am exactly as you describe in your post – stuck writing procedural code with dodgy logic, serving it inline with HTML and making do because it works. I have about 5 books on OOP principles, and I have read and digested them all. I can read OO code. I just cannot seem to make the leap from what I’m doing now to what I should be doing.

    I don’t want to be in the same position, 5 years down the road, writing the same code I’m writing now.

    I am the only developer at work, which means nobody to learn from. I have a much more knowledgeable developer friend pushing me towards OOP and good design practises but he’s on the other side of the world and time zone differences and work get in the way. What do I do? How do I find someone who is comfortable sitting down with me and telling me where I’m going wrong and how to put it right?

  9. Firstly, thanks for the link =)

    You wrote some good points. I have noticed the similar “stuff” being around in certain other languages (like Java) that makes them kind of frustrating to learn even when you already know a thing or two about programming. I also think that I did write poor code in PHP, before I was exposed to frameworks and certain books (Code Complete, Pragmatic Programmer, etc.) about programming theory – things that I might’ve learnt if I wasn’t self-taught.

    Jem: I think you should choose a PHP framework. Personally I’d recommend Zend Framework, but there are others too. Then, stick to the common best practices for the framework in question, which should make you write at least somewhat better code. Next, join a relevant IRC channel – there are usually people that are willing to point out mistakes or just offer general advice if you ask nicely and show them the code you’re struggling with. Reading the books I mentioned can be helpful too if you haven’t yet.

  10. “I went from looking at objects as namespaces to a representation of something.” Yup, ditto here, up until only about a year ago. Disgraceful, right? But PHP (and co-workers) were forgiving… though maybe they shouldn’t have been…

    Nice article!

  11. im really wanting to learn php but im on the “high dive” and can’t figure out how to jump in i’ve rented book from the library and searched online but i am still very confused about how to use the codes i am getting really frustrated about not being able to understanding it because every place i try to learn it from is differn’t from the last and just shows you how to make some generic little program and not how to make costome ones

Comments are closed.