Is it possible to restrict a function written in a class constructor to certain methods within a class like so:
class Myclass {
public function __construct()
{
// run a function here, but make it assessible to specific methods
// method_one(), method_two(), method_three()
}
public function method_one()
{
}
public function method_two()
{
}
public function method_three()
{
}
public function method_four()
{
// function should not be assessible here
}
}
I understand that the function can simply be put in the methods where it is needed, but what if I have so many methods like that, say 10, won't it mean that the function will be repeated so many times?
EDIT
Here's the live scenario:
I'm building a MVC app that checks if a user has updated his/her profile details. The controller class has methods that are called when a page is visited. So, I want for every page that is visited (apart from the profile page) to redirect to the profile page if the profile hasn't been completed.
So, with the current code structure I have, is this possible?