I have a class with a
validId($id) method that is called by the constructor and by
public function load($id). The method queries the database to see if the id exists and returns true/false.
The constructor optionally takes an
$id (if no $id, then the object will be empty).
The constructor checks the $id with
validId($id), and if it passes, then it calls
I should not take
validId() out of
load() is public and the input has to be checked!
The same goes for the constructor.
How do I avoid calling
validId() twice? I was thinking I could add a parameter to
load($id,$check_id), but that would be ridiculous. You can't give clients the option to not validate data!
I could add a protected property like
$id_is_valid that gets set to true by
validId($id). But how do I know the value that was valid is the same one being received by my
I'm using PHP.
Hopefully this isn't a stupid question.