I currently have a function where I’m trying to refer to the $id in the class but it doesn’t work:
public function getCourseInfo($cid = $this->id, $all = false)
{
}
This is my class:
class Course
{
protected $course;
protected $id;
public function __construct($cid)
{
$id = $cid;
$this->course = $this->getCourseInfo($this->id);
}
public function getCourseInfo($cid = $this->id, $all = false)
{
}
}
Everyone in this thread is giving correct answers but no one gave a full code sample hence I’ll post my suggestion:
As you’ll notice I’ve omitted the course id parameter from getCourseInfo() simply because it’s not needed if you instantiate the class with a course id.
Secondly, I don’t think you should call getCourseInfo in the constructor because the information will only be needed at a later point. Also, I added “caching” to the function so that you don’t fetch data twice.
Obviously there’s a high chance that I could be wrong having not seen your code but I feel this is a better structure of the code.