"Call to Undefined Function" error when calling a class function

Asked

Viewed 172 times

3

I have a function to convert the date, but is returning me an error that I could not adjust:

Follows code:

<?php

class Prog{

    private $DtBase;

    public function setdata($DtBase){
        $this->data = $DtBase;
    }
    public function getdata(){
        return convertData($this->data);
    }
    public function convertData($data){
        $data = Datetime::createFromFormat('d/m/Y', $data);
    return $data->format('Y-m-d');
    }
}

?>

Error calling the Function convertData:

Call to Undefined Function convertData() in Prog.php on line 11

Any hint ?

  • A tip, in English Data means "data" and Date means dia/mês/ano/etc, it would be interesting to use the names like this convertDate when referring to a day.

  • Yes, I forgot to change why the name of Function before was converterData.

1 answer

4


In getData() you need to specify who is the summoner(owner) of this function(method), as in the case is the same object is used the $this

Change:

return convertData($this->data);

To:

return $this->convertData($this->data);

Browser other questions tagged

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