Search code examples
phpclassinheritanceextend

php call function in Class that extends values from another calss


I am calling a function from a class that extends the value from another class. 2 question: 1. this is the right way? 2. I can't call the function getTaskID, got error: Call to undefined method PythonTask::taskID()

TaskC.php

class Task{
protected  $taskID=0;

  public function __construct(){}    
}

class PythonTask extends Task{


    private $isCustom=0;
    public function __construct($taskID=0,$isCustom=0){
       parent::__construct();
       $this->taskID=$taskID;
       $this->isCustom=$isCustom;
    }

   public function getTaskID(){
      return $this->taskID();
   }

}

include_once('TaskC.php');

$pythonTask = new PythonTask;
echo $pythonTask->getTaskID();

any advice? and recommendation for a good extends guide?


Solution

  • try to change

    return $this->taskID();
    

    to

    return $this->taskID;
    

    taskID() is not a function