I wanna make a syntax like jquery in php, I wrote that class:
class events{
public function auth($user, $pass, $callback){
$status = 0;
if($user and $pass){
$status = 1;
}
call_user_func($callback, $status);
}
public function login(){
echo "Welcome!";
}
}
$events = new events;
$user = "u";
$pass = "p";
And that's Jquery like syntax:
/**
* Jquery type callback function
*/
$events->auth($user, $pass, function($status){
if($status){
$this->login();
}else{
echo "Fail";
}
});
Everything is OK except $this variable I used outer that class methods, I cannot use the callback function as a internal function for using $this into that function codes. Can I correct that error by changing something in my class ?
$thisin classes.$events->login()instead of trying$this->login()?