Alex Rivera | Logout

PHP: Calling a user-defined function inside constructor?

Asked 2010-12-02T13:41:55.640
11

I have a class userAuth inside its constructor I have added code to check the user is valid or not, if there is no value in session then I check cookies (as a part of "Remember Me" feature), if there is some value inside cookies then I call a function ConfirmUser to check its authenticity from database. On the basis of value returned by the confirmUser function I am returning a bool (true or fales) value in constructor.

I have created my class as:

<?php
    class userAuth {

        function userAuth(){
            //code
        }

        function confirmUser($username, $password){
                   //code
        }
    }

    $signin_user = new userAuth();

?>

confirmUser function take two string type parameters and return return a integer value of 0, 1, 2.

I can't add code of confirmUser function inside the constructor as I am using this function at some more places in my application.

So, I want to know how to call a user-defined function inside constructor in PHP. Please help.

Thanks!

Edit
Report

1 Answer

30

$this->nameOfFunction()

But when they are in a class, they are called Methods.

answered 2010-12-02T13:55:24.790

Your Answer