Possible Duplicate:
PHP method chaining?
I had a function for create user, like cruser inside class and set password like setpw.
I want to create a validate function to check the username and password and I want use it like this:
$a = new class abc();
$a->cruser->chk();
$a->setpw->chk();
Need 2 different function or same can do?
It’s so elegant, how can I define this?
class abc {
function cruser { }
function setpw {}
//??? - need to define here chk or to different class?
}
for PHP 5.2/5.3.
How can I achieve this, or is there a better way?
This is called method chaining. Your methods need to return the instance of the object being called.
To set a username and password and validate, you’d call like this: