Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Lee Nolan
Lee Nolan
21,690 Points

Is PHP a bit 'messy'?

So having become pretty well versed in HTML, CSS, JavaScript and jQuery, I have started to venture into the server side with PHP.

I am at the 'build a basic website with PHP' course and I am liking features like using include files to generate headers and footers and things like that, but I can't help but feel that the way it gets mixed in with all the HTML looks really messy...especially when JS and CSS are encouraged to be completely separate.

Are there 'tidier' ways of working with PHP or is that pretty much how it is?

3 Answers

Benjamin Larson
Benjamin Larson
34,055 Points

PHP CAN be messy, and historically it has a reputation for its users producing hideous code, both logically and syntactically but this doesn't have to be the case. The same could largely be said of Javascript in the past, because both of them were easy to pick and use, even if you had little to no idea of what you were doing.

Separating logic and presentation is a problem with most server-side languages and often necessitates some sort of framework and/or templating engine on top of a base language in order to adhere to an MVC (Model-View-Controller) pattern. This is why with Ruby you'll eventually learn Rails, with C# you'll learn MVC with ASP.NET Core.

With PHP you have options like Laravel or Zend, or other options for micro frameworks and stand-alone template engines (Slim and Twig, for example). It can still seem messy, but the language and standards within the community have matured and building well designed, modern applications is very much a viable option in PHP among the other choices.

This is pretty much how you have to use it.

I actually tried to learn PHP once, but I quit because it was a little messy.

I recommend Python or Ruby for back-end. There's even a JavaScript framework called Node.js so that you can work on the back-end with JavaScript.

Lee Nolan
Lee Nolan
21,690 Points

Thought as much! I have been looking at node and I guess it would be easier given that I already have a fair bit of JavaScript under my belt. I will finish the current PHP website course and see how I feel!

Sounds good! :smile: