r/PHPhelp • u/TheHeenie • Jun 17 '19
Development in PHP without a framework / Mixing procedural and OO design in PHP
So as a fairly new person to web design using PHP, and still fairly new to it in general, I've decided to get my hands dirty and begin without any framework to really get a comprehensive understanding of what's really going on. The only other times I've dove into web development was in the Spark Framework for Java 8, where everything was pretty heavily abstracted. Its been a bit of a slog, but I feel like I'm slowly starting to understand the gist of things, and once I wrote a router everything began to flow a lot better.
So with my newness established, my real question is, the deeper I get into this, the more I feel like I'm going to have to essentially write an entire framework to properly adhere to Object Oriented Principles. It really seems inefficient (or at very least time consuming) to try to match web dev to pure OO, and I'm really tempted to leave a few choice areas practically procedural to make the entire project flow better. Its become a real nightmare particularly as I get further into separating my php from my html, ob_start() and ob_get_clean() have been the workhorses here, but I find them really clumsy to use.
Now I know I could just give up and switch to simply using a framework and a template engine, but I've found this whole process really educational, and I'd like to see it to the end. I've found it difficult to find resources and info to improve my design, most questions I search end up referring to using a framework. I'd really appreciate any thoughts and advice going forward!
2
u/halfercode Jun 17 '19
In general, I would say that if you have some solo projects, use your own framework. I agree there is a good learning opportunity here.
However, if you have any projects where someone else will maintain them after you, don't practice on your colleagues - use a tried-and-tested framework that is still in security/feature maintenance.
1
0
u/gsogso111 Jun 17 '19
Write you own framework. It's not a hard to do.
All you need is knowledge about MVC pattern, namespaces and PSR (0,1,2,4)
First you have to lean how to use composer and how to write composer.json. Other way is to write own autoloader
In my sites i use my own framework, it is a simple, lightweighted and very fast. Of course, i know symfony/laravel etc, but i think that is a hard and slow frameworks.
Do your own framework
3
u/gui_ACAB Jun 17 '19 edited Jun 17 '19
I've done it before and ended up with a simple framework i really enjoyed.
What helped me at the time was to check others frameworks like Slim and debug them. By debug i do mean set a breakpoint at the top entry level and go from there.
I've learned how to properly apply design patterns because they were needed.
Giving an example. The Hydrator pattern i believe I've checked from Doctrine. I didn't had the need of it while i coded in csharp but it's really usefull in PHP.