1

So I have a class and I created an object of the class outside of it. When I try to execute the function createSummonerBasicArray() I get this error "Fatal error: Call to undefined function prepSummonerBasic()". So apparently it is saying prepSummonerBasic() does not exist. I tried making both functions public and it didn't change the error. New to PHP btw.

Class SummonerSearch{

    function prepSummonerBasic($summoner, $server) {

    }

    function createSummonerBasicArray($summoner, $server){
        $summonerBasic = prepSummonerBasic($summoner, $server);
    }

};

$obj = new SummonerSearch('crippy', 'na');
$obj->createSummonerBasicArray('crippy','na');
2
  • Have you tried $this->prepSummonerBasic(...) ? Commented Oct 14, 2016 at 4:14
  • I didn't but that was the solution. Commented Oct 14, 2016 at 4:18

2 Answers 2

3
function createSummonerBasicArray($summoner, $server){
    $summonerBasic = $this->prepSummonerBasic($summoner, $server);
}

you must call it with $this->, not like in java

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the fast reply! That worked but can you explain a little about why $this-> is necessary?
0

Try this with used static keyword:

<?php
Class SummonerSearch{
    public static function prepSummonerBasic($summoner, $server) {
        echo $summoner;
    }

    function createSummonerBasicArray($summoner, $server){
        $summonerBasic = self::prepSummonerBasic($summoner, $server);
    }
};

$obj = new SummonerSearch('crippy', 'na');
$obj->createSummonerBasicArray('crippy','na');
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.