PHP - 从类调用类

Hello i looking for a way to call class function from another class.

i've tried diffrent PHP ways such as the classic way, to call class from class.

http://pastebin.com/X5VfaChr

require_once "user.php";
$user = new UserAction();
class htmloutput{
    public function WebSite(){
        $user->Moshe();
    }
}

Its shows me this error:" syntax error, unexpected 'new' (T_NEW), expecting function (T_FUNCTION)" i dont know about more ways to call a class.

I'll be happy to get helping and learn somethin' from that.

Have Good day, Baruch

Try to get the instance inside your function, as the following:

require_once 'user.php';
class htmloutput {
    public function WebSite(){
        $user = new UserAction();
        $user->Moshe();
    }
}

Besides the comment from Abhik Chakraborty, this fixes the issue coming next:

It's all about scope. Google for DI injection:

require_once "user.php";
$user = new UserAction();

class htmloutput {
    public function WebSite(UserAction $user) {
        $user->Moshe();
    }
}