Skip to main content
1 of 3
Paul
  • 4k
  • 2
  • 23
  • 38

Another recommendation apart from all of the good ones you have already received.

Don't create variables that are not variables.

                // Assign variables to returned data 
                $passwordDB = $user_data->password;
                $passwordDB2 = $user_data->password2;
                $first_name = $user_data->first_name;
                $last_name = $user_data->last_name;
                $email = $user_data->email;
                $users_roles_id = $user_data->users_roles_id;

These variables are assigned once and used once (or possibly twice), however they are never modified. They only abstract away the details of what is being done later in the function. Accessing the object properties is more descriptive than referring to local variables. When you have a local variable you have to track back to where it was last set to see its value. Also, there is less clutter without these lines that do very little.

Personally I like to handle data in larger chunks rather than lots of fields spread everywhere. I would be using arrays to hold the data and avoid line by line first name, last name, email access.

Paul
  • 4k
  • 2
  • 23
  • 38