r/PHPhelp • • Sep 06 '16

Is it necessary to use a PHP framework?

Hello, I'm a beginner PHP developer (I know decent amount of stuff, enough to make a basic forum) I've never used a framework and people have recommended me to use Laravel. Could someone kindly tell me why I need to use a framework? Is it a must? Is coding from scratch without a framework a bad approach? By the way, I'm about to build a StackOverflow+Reddit styled website. So its going to be a huge project.

13 Upvotes

13 comments sorted by

4

u/[deleted] Sep 06 '16

Not a must. It all depends on the scale of your project. Some frameworks will serve better purposes than others depending on the project

But yes, I would recommend Laravel. It's great and fairly easy to learn

1

u/invisibo Sep 07 '16

To add to Laravel, there's tons of tutorials on laracasts that provide excellent information. And in order to use Laravel properly, you must follow MVC patterns, which can be pretty tricky starting out.

3

u/gin_and_toxic Sep 06 '16

I'm about to build a StackOverflow+Reddit styled website. So its going to be a huge project.

You'll definitely need it. Especially if you're involving multiple collaborators, having a framework will really help.

On a side note: isn't that a bit too ambitious of a project for a beginner?

2

u/Ickle_Chris Sep 06 '16

Not really, they likely only mean a simplified version with some of the core features. Attempting to recreate a site you know well like that seems like a decent project IMO

1

u/HauntedMidget Sep 07 '16

Sure, but beginners usually struggle with time and complexity estimates. Even the core features will take a lot of time to implement.

Another problem is that projects that are too ambitious rarely get completed. It's very easy to lose interest when you don't see daily progress due to the scope of the project. Splitting the tasks into smaller ones help, but it's much harder to do without prior experience.

2

u/rogue780 Sep 06 '16

No. It can be very helpful though. A lot of times popular frameworks provide very common tasks so you don't have to reinvent the wheel and and ironed out security flaws. Coding from scratch can be more performant, but you're going to really need to make sure you know what you're doing for anything production scale or where security might be a concern.

1

u/halfercode Sep 06 '16

Often I will start with something really simple, like a home-made framework or a microframework like Slim. As long as it is reasonably modular, it is not too much of a pain to port it over to something bigger if you need to. Of course, you can hop onto a full-fat framework immediately if you wish, but if you are a beginner in both PHP and (say) Laravel, it will slow your development down to start with.

1

u/Mike312 Sep 06 '16

It's not necessary, but it will save you a bunch of time. For a disclaimer, i'm the type of programmer who likes to dig into things to figure out why/how they work. Larger frameworks will have more features, but also have much more overhead. Do some research, see what the pros/cons of each type of framework are. The larger frameworks can also be a bit more of a pain in the ass to diagnose issues.

I personally use a framework called Flight for php that handles the URL rewriting/routing but doesn't add anything else like helper functions, and then have a set of helper functions I've built and maintain. It works well in the environment I work in, but it would definitely be a little more trouble in a larger, more distributed environment.

1

u/Ultimater Sep 06 '16

If you're going to build something very simple, a framework would only hurt performance and complicate something simple. But if you're going to build something worthwhile, you should be using a framework. Sure, you could get code to work without any specific design pattern, but the code won't be very easy to understand or maintain. You could, of course, write your own "framework" to follow your own "design pattern" mentality, but why reinvent the wheel if it's already done?

Laravel is probably the best PHP framework out there to learn if not simple due to its marketing popularity. There's many frameworks out there, but if a team had to collaborate within the same framework, Laravel is an excellent choice. Zend is an ok choice, as it's built by the same company that maintains PHP, but it's rather slow and a bit too abstract to make immediate usage out of. The best part is you can take a certification test in it if you master it and show it off in your resume. (the test you take in person at your local pearsonvue)

But, yeah, for a stackoverflow+reddit styled site, you should really be using a framework. But as you're a beginner, it might be a bad idea to jump directly to learning a framework if you don't understand the PHP basics. I'd suggest check out some Laravel tutorials out there and try to write code to the same style of code you find out there. When you get the hang of it, then approach your project. Otherwise, you're more than welcome to try to build something from scratch, without a framework, and see how hard it is. Writing a framework is its own project. Without some kind of framework available to your project, you won't be able to take advantage of proper design patterns and the whole architecture of the project will suck. But if this is solely for learning purposes and second-rate is acceptable, go for it. Just try to steer clear of the common PHP mistakes out there like SQL injection, not escaping output, XSS, and other security-related concerns.

1

u/aqeeliz Sep 07 '16

Like many people here have suggested, frameworks can help in big projects, though for a beginner I would recommend sticking with native PHP for a while. It's better to first get some good understanding of how things work, before trying to find a way to do them with less effort.

1

u/akujinhikari Sep 07 '16

I wrote an entire site with PHP and jQuery when I was trying to get hired as a developer. Fast forward a year later, and I had been programing in Angular professionally. When I went back to look at my site, it was awful. I realized that I needed a framework. The scope of the site was just too large for me, considering I'm not a PHP developer. That being said, I learned so much from that first site that I highly recommend you write it in pure php first them decide if you need a framework from there.

0

u/[deleted] Sep 07 '16

Could someone kindly tell me why I need to use a framework?

You don't need to. Its convenient if you create a huge application/site. Otherwise it's more or less unnecessary.

Is it a must?

Nope.

Is coding from scratch without a framework a bad approach?

No, it isn't.