How is construct function working even when variable is assigned null value?

I’m unable to understand the function of __construct here. I know that in any class __construct runs anytime the class is instantiated. However, my curiosity is, when $marks is defined as null in the __construct function, then why it is checking for its value in the if statement of __construct? Won’t it always return false?

class Marks_Manage
{
    public $mark_id;
    public $exam_id;
    public $class_id;
    public $subject_id;
    public $marks;
    public $attendance;
    public $student_id;
    public $marks_comment;
    public $created_date;
    //current_time( 'mysql' );

    public function __construct( $marks = null ) 
    {
        if($marks)
        {
            global $wpdb;
            $table_name = $wpdb->prefix . "marks";
            $mark_data = $wpdb->get_row( "SELECT * FROM $table_name WHERE mark_id=".$marks);
            $this->mark_id = $mark_data->mark_id;
            $this->exam_id = $mark_data->exam_id;
            $this->class_id = $mark_data->class_id;
            $this->subject_id = $mark_data->subject_id;
            $this->marks = $mark_data->marks;
            $this->attendance = $mark_data->attendance;
            $this->student_id = $mark_data->student_id;
            $this->marks_comment = $mark_data->marks_comment;

        }
    }

Read more here: How is construct function working even when variable is assigned null value?

Leave a Reply

Your email address will not be published. Required fields are marked *