I try to use $this in a nested function in my class.
I call the method with:
$check_membership = $this->setAuthorisation($posted_username, $ldap_connection);
the method looks like:
private function setAuthorisation($posted_username, $ldap_connection)
{
    // split the posted username for filtering common name
    $temp_var = explode('\\', $posted_username);
    $cn_name = end($temp_var);
    // filter parameter for ldap_search
    $filter = "objectClass=*";
    // search attribute to get only member
    $attr = array("member");
    // possible membership status:
    // group_membership: "null": No access to enter the page.
    // group_membership:    "1": Access to the page, but no admin rights.
    // group_membership:    "2": Access to the page with admin rights.
    /**
     * perform the setMembershipUser for authorisation the "user" group
     */
    function setMembershipUser($ldap_connection, $cn_name, $filter, $attr)
    {
        // search for user in the authorized ad group "user"
        $user_result = ldap_search($ldap_connection, GROUP_USER.",".BASE_DS, $filter, $attr);
        // reads multiple entries from the given result
        $user_entries = ldap_get_entries($ldap_connection, $user_result);
        // check if cn_name is in $user_entries
        if (preg_grep("/CN=".$cn_name."/i", $user_entries[0]["member"]))
        {
            $this->group_membership = 1;
        } 
        else 
        {
            $this->group_membership = null;
        }
    }
    setMembershipUser($ldap_connection, $cn_name, $filter, $attr);
    return $this->group_membership;
}
in the function setMembershipUser I got the Error "Fatal error: Using $this when not in object context in..."
Can I use $this in nested functions? The outer function is in my class.
 
     
     
    