Error with php Fatal error class: Uncaught Error: Call to Undefined Function run_search()

Asked

Viewed 1,014 times

1

I tried to create a class, and getting the error below I already researched more not found why is giving this error.

Error:

Fatal error: Uncaught Error: Call to undefined function run_search() in D:\xampp\htdocs\Github\astra\class\buscaAnimes.class.php:17 Stack trace: #0 D:\xampp\htdocs\Github\astra\index.php(11): buscaAnimes->get_busca('21') #1 {main} thrown in D:\xampp\htdocs\Github\astra\class\buscaAnimes.class.php on line 17

Class::

    <?php

    class buscaAnimes{

    private $idAnime;
    private $urlMal;

    public function __construct(){

    }

    //Pega a id passada pelo usuario e atribui ao $idAnime
    public function get_busca($b){
        $this->idAnime = $b;
        $resposta = run_search();
        return $resposta;
    }

    private function run_search(){
        if(!isset($this->idAnime) & empty($this->idAnime)){
            return 'Erro: É necessario um id para fazer a busca';
        }

        $this->urlMal = 'https://exemplo.com/anime/'. $this->idAnime .'/';

       $resposta = curlSearch($this->urlMal,'get');

       if($resposta[1] != 200){
           return $resposta[1];
       }else{
           $resposta = $resposta[0];
           return $resposta;
       }
    }
}

?>

1 answer

2


This error means that there is no function run_search, what exists is the function run_search within the class buscaAnimes, lacked to add the $this->:

//Pega a id passada pelo usuario e atribui ao $idAnime
public function get_busca($b){
    $this->idAnime = $b;
    $resposta = $this->run_search();
    return $resposta;
}
  • I got it, I tested it and it worked. Brigado!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.