oops in php
Inherited Static Behaviors in php
- staic properties and methods are inherited
- visibility modifiers function the same
- inherited static properties are shared variables
- changes to the parent value change subclass values
- changes to a subclass value change the parent value
Example:
<?php
class Student{
public static $grade=['Fresher','Junior','Senior'];
}
class PartTimeStudent extends Student{
}
echo PartTimeStudent ::$grades[0];//Fresher
PartTimeStudent ::$grade[]='Super Senior';
echo implode(',',Student::$grades);//Fresher,Junior,Senior,Super Senior
Example2:
<?php
class Student{
public static $total_students=0;
}
class PartTimeStudent extends Student{
}
Student::$total_students++;
Student::$total_students++;
Student::$total_students++;
PartTimeStudent :: $total_student++;
echo Student :: $total_students;//4
echo PartTimeStudent :: $total_students;//4