The biggest advantage of the OOP vs procedural programming in PHP to my understanding is the sort of separation of the function names (sort of namespace).
So now when we have namespace since version 5.3, what do you think - For most cases (small to mid websites), when we need fast and again structured code, do the use of namespace + prodecural programming gains signifficant advantage over defining and writing in OOP.
Advantages:
- structured
- faster code/development
- again we can define something like private functions within the namespace starting with "_" knowing that we don't need to use them
- etc..
Code example:
namespace User;
function setPassword ($user_id) {
$pass = _generatePassword();
$sql = 'UPDATE `users` SET `password` = '.escape($pass).' WHERE `user_id` = '.escape($user_id);
$result = mysql_query($sql);
if (mysql_affected_rows() == 1) return $sql;
else return $sql;
}
function _generatePassword () {
$char = '0123456789abcdefghijklmnopqrstuvwxyz';
$str = '';
for ($i = 1; $i <= 6; $i++) {
$str .= $char[mt_rand(0, strlen($char))];
}
return $str;
}
Usage:
$user_id = 5;
User\setPassword($user_id);
I am asking for opinion. I know that it is just to the developers style, but maybe I am missing something.
PS. For most cases (small to mid websites) - I mean when you do websites for clients which are mostly 1 time development, and a little feature improvements in the long run.