I am learning Classes and OOP and PDO and all that stuff ( I know legacy php, so, can write php 4.x scripts with messy code ^^ ).
So, started to transform over my base template system to the new code so far so good, sessions and PDO are in classes , pagination system is in a class, users are in a class (basicaly everything).
Here's my question.
I use 2 functions to do a single thing first function is to get the user rights and it looks like this
function u()
{
if ($_SESSION['loggedin'] == 1)
{
return true;
}
else
{
return false;
}
}
As you can see, it just return true or false based on session (code contains more but is for admin/staff ). Should I also convert this to a class ? or is it useless ? and leave it as a function ?
Then my second function is to get some arrays ( used for group system)
function arr($string, $separator = ',')
{
//Explode on comma
$vals = explode($separator, $string);
//Trim whitespace
foreach($vals as $key => $val) {
$vals[$key] = trim($val);
}
//Return empty array if no items found
//http://php.net/manual/en/function.explode.php#114273
return array_diff($vals, array(""));
}
As this function is only used for the group update and to get info from what groups users are in is it in a function
So my question, as far as i understand OOP does it mean that you write code to make things 'easier', so should I also make a class of those functions to make things easier or is it useless as it makes it harder ?
if (u())
{code code};
if (a());
{admin code}
vs
$u = new User;
if $u->rank(user){
code code
}
if $u->rank(admin){
admin code
}
Base code can be found here it is to give a idea what I am rewriting to pdo.