Code Review:
Naming Convention:
$variableNames
andfunctionNames()
should be in camelCase,ClassNames
should be in CamelCaps. Keep this convention to make your code more readable!Use an autoloader: To stop you from being worried about loading classes, use an autoloader. See
spl_autoload_register()
spl_autoload_register()
for registering an autoloading function.Don't use Singletons: Do not use Singletons. Singletons are global, they introduce hidden dependencies to your code and make it unpredictable and untestable.
No explicit dependncies in sight: What does your
user
object need in order to work? I'm guessing a database connection, maybe even a user_id? Why are you not passing those to theuser
's constructor?$user = new User($db, $_SESSION["user_id"]); // For example
How to improve
This code, contrary to popular belief, is not MVC. MVC stems from good OOP practices, and the separation of concerns. The idea is to separate your application into three major layers:
- The Input: The Controller layer.
- The Output: The View layer.
- The Processing and Logic: The Model layer.
Where each has its own job and responsibilities, its own set of objects, and its own role in the application.
I propose you start with learning about OOP, avoid PHP frameworks, and once you grasp OOP, start looking at MVC.
Code Review:
Naming Convention:
$variableNames
andfunctionNames()
should be in camelCase,ClassNames
should be in CamelCaps. Keep this convention to make your code more readable!Use an autoloader: To stop you from being worried about loading classes, use an autoloader. See
spl_autoload_register()
for registering an autoloading function.Don't use Singletons: Do not use Singletons. Singletons are global, they introduce hidden dependencies to your code and make it unpredictable and untestable.
No explicit dependncies in sight: What does your
user
object need in order to work? I'm guessing a database connection, maybe even a user_id? Why are you not passing those to theuser
's constructor?$user = new User($db, $_SESSION["user_id"]); // For example
How to improve
This code, contrary to popular belief, is not MVC. MVC stems from good OOP practices, and the separation of concerns. The idea is to separate your application into three major layers:
- The Input: The Controller layer.
- The Output: The View layer.
- The Processing and Logic: The Model layer.
Where each has its own job and responsibilities, its own set of objects, and its own role in the application.
I propose you start with learning about OOP, avoid PHP frameworks, and once you grasp OOP, start looking at MVC.
Code Review:
Naming Convention:
$variableNames
andfunctionNames()
should be in camelCase,ClassNames
should be in CamelCaps. Keep this convention to make your code more readable!Use an autoloader: To stop you from being worried about loading classes, use an autoloader. See
spl_autoload_register()
for registering an autoloading function.Don't use Singletons: Do not use Singletons. Singletons are global, they introduce hidden dependencies to your code and make it unpredictable and untestable.
No explicit dependncies in sight: What does your
user
object need in order to work? I'm guessing a database connection, maybe even a user_id? Why are you not passing those to theuser
's constructor?$user = new User($db, $_SESSION["user_id"]); // For example
How to improve
This code, contrary to popular belief, is not MVC. MVC stems from good OOP practices, and the separation of concerns. The idea is to separate your application into three major layers:
- The Input: The Controller layer.
- The Output: The View layer.
- The Processing and Logic: The Model layer.
Where each has its own job and responsibilities, its own set of objects, and its own role in the application.
I propose you start with learning about OOP, avoid PHP frameworks, and once you grasp OOP, start looking at MVC.
Code Review:
Naming Convention:
$variableNames
andfunctionNames()
should be in camelCase,ClassNames
should be in CamelCaps. Keep this convention to make your code more readable!Use an autoloader: To stop you from being worried about loading classes, use an autoloader. See
spl_autoload_register()
for registering an autoloading function.Don't use Singletons: Do not use Singletons. Singletons are global, they introduce hidden dependencies to your code and make it unpredictable and untestable.
No explicit dependncies in sight: What does your
user
object need in order to work? I'm guessing a database connection, maybe even a user_id? Why are you not passing those to theuser
's constructor?$user = new User($db, $_SESSION["user_id"]); // For example
How to improve
This code, contrary to popular belief, is not MVC. MVC stems from good OOP practices, and the separation of concerns. The idea is to separate your application into three major layers:
- The Input: The Controller layer.
- The Output: The View layer.
- The Processing and Logic: The Model layer.
Where each has its own job and responsibilities, its own set of objects, and its own role in the application.
I propose you start with learning about OOP, avoid PHP frameworks, and once you grasp OOP, start looking at MVC.