What are the OOP principles that should be considered when working with variables in PHP classes?

When working with variables in PHP classes, it is important to consider the OOP principles of encapsulation, inheritance, and polymorphism. Encapsulation ensures that variables are only accessible within the class, protecting them from external interference. Inheritance allows classes to inherit variables from parent classes, promoting code reusability. Polymorphism enables variables to be treated as instances of their parent class, allowing for flexibility in the way they are used.

class Person {
    private $name;
    
    public function setName($name) {
        $this->name = $name;
    }
    
    public function getName() {
        return $this->name;
    }
}

class Student extends Person {
    private $studentId;
    
    public function setStudentId($id) {
        $this->studentId = $id;
    }
    
    public function getStudentId() {
        return $this->studentId;
    }
}

$student = new Student();
$student->setName("John Doe");
$student->setStudentId(12345);

echo $student->getName() . " - " . $student->getStudentId();