Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to use a method from within another method in a class. I don't have much experience in PHP5 OOP, and I looked around for answers, but couldn't find any. I'm trying to use getClientInfo() in sendRequest(), which is in the same class.

class DomainHandler {

    public static function getClientInfo($db, $client_id)
    {
        //Do stuff
    }

    public static function sendRequest($details)
    {

        require_once('MySQL.class.php');
        $db = new MySQL;

        getClientInfo($db, $client);
    }
}

And it tells me:

Fatal error: Call to undefined function getClientInfo()

I've also tried

parent::getClientInfo($db, $client); 

and

$this->getClientInfo($db, $client);

to no avail.

Any ideas?

question from:https://stackoverflow.com/questions/2220809/calling-a-method-from-another-method-in-same-php-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
327 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's a static method so you have to call it with self::getClientInfo or DomainHandler::getClientInfo.

Also: You might want to read up on object oriented programming since it looks like you have not yet understood what it's really about (it's not just putting functions between a class Foo { and } and putting public static in front of them)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...