Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Smart factory class. I want to build a smart user class based on the factory model. But i have some troubles grasping it, basicly i want to do something like this:
class bla {
function bla()
{
$this->lol();
}
function ()
{
echo "Yup!";
}
function ly()
{
echo "Yip!";
}
}
class userFactory {
private $userID;
function userFactory($userID)
{
$waa = new bla();
return $waa;
}
}
try {
$user = new userFactory(1);
$user->lolly(); //Error
} catch (Exception $e) {
echo $e->getMessage();
}
The class will then return different classes according to the users permissions and functions and such. Is it possible to do something like this?
Thanks.
The constructor of a class is unable to "return." You will either need a method to call in your factory or return the newly created object via a reference you pass into the constructor.
The recommended route is the former over the latter.