Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the register method is tied to the object (the instance, not the class), the I'd have it use the internal properties which have to be set in advance. So, you instantiate a user, set the properties and then call $user->register().</p> <pre><code>$user = new User(); $user-&gt;firstName = 'name'; //$user-&gt;setFirstName('name') could also work $user-&gt;lastName = 'last name'; // for this to work, the properties have to be public $user-&gt;register(); </code></pre> <p>User A should only be able to register itself, and not anything else.</p> <p>If you use a method with parameters, you could basically register anything (not only a user).</p> <p>Also, if registration means writing the parameters to a database, a method that only uses the internals of the user object is more robust. If you decide to change the registration mechanism (if you need some other info from the user object), only the user class has to be modified.</p> <p>Edit:</p> <p>Now that I've thought about it a bit more, I think I'd make another class to register users, it would take the entire user object and add a role or whatever and save it to the database. That way, a user object is a bit simpler, and does not need to know how it is registered or unregistered, and if the registration mechanism changes, the users can stay the same.</p> <p>Edit 2:</p> <p>Be careful when setting object properties from a method that is not a really a setter (like you would in the register($fname, $lname, ...)). The same approach has brought me headaches when "something" would change my object for no apparent reason, and I couldn't find a setter or a direct call to the property anywhere in code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload