Creating your own MVC (Model-View-Controller) structure in plain PHP without any frameworks or Composer packages can be a great way to learn how things work behind the scenes. But it also brings some real challenges that you start to feel early on.
Here’s what I learned during the process, explained in a very simple way.
In my Git account , Check this having all this code.
1. 🧩 You Have to Include Everything Manually
Unlike Laravel or Symfony, there’s no autoloading. That means:
require_once 'models/User.php';
require_once 'controllers/UserController.php';
require_once 'views/home.php';
Every file you want to use must be loaded manually using require_once. If you forget one, you get an error.
It’s like putting together a puzzle – you have to remember every piece.
2. 🚪 Redirecting Users Manually
In frameworks, redirects are simple (return redirect('home')), but in raw PHP, you need to do:
header('Location: view/home.php');
exit;
It works, but feels low-level. You’re working closer to the metal.
3. 🤖 PHP IntelliSense Doesn’t Work Without Proper Typing
If you’re using a $pdo object for database queries and don’t define its type, your code editor won’t help you with autocomplete or suggestions.
So, you need to add:
/** @var PDO */
private $pdo;
Without this, it feels like you’re coding blind — no help from your IDE.
4. 🔐 You Have to Handle Sessions Everywhere
In modern frameworks, session handling is automatic. But in pure PHP, every page that uses session data needs this at the top:
session_start();
If you forget it — boom — nothing works.
5. 🧱 Everything Is Connected, But Feels Messy
Even though you keep files separate — models, views, and controllers — they are all connected manually, either by class inheritance or by using require_once.
It works, but managing those links gets messy as your project grows.
6. 🧬 Views Are Mixed with PHP
Since there’s no template engine like Blade or Twig, you end up writing HTML with embedded PHP like this:
<h1><?php echo $user['name']; ?></h1>
It works, but it’s not very clean. Your logic and presentation are tightly mixed.
🔚 Final Thoughts
Building an MVC from scratch in PHP is a great learning experience. You understand how web requests work, how files connect, and how sessions and redirects function. But it’s also clear why frameworks exist — they save time, reduce errors, and keep things organized.
If you’re learning PHP, try building one yourself — you’ll appreciate frameworks even more later on!
