Create a class that inherits from a parent class
Define a class that inherits from another
class MyChildClass extends MyParentClass
{
function MyChildFunction()
{
return "abc";
}
}
Now, objects of class MyChildClass can call MyChildFunction(), but objects of MyParentClass can’t.
Overriding functions in a parent class
class MyChildClass extends MyParentClass
{
//Override parent class function MyParentFunction()
function MyParentFunction()
{
return "abc";
}
//If we wanted to call the function in the parent class
function SomeChildFunction()
{
$Something = parent::MyParentFunction();
}
}
Protected members
Members (variables, functions, etc) can be defined with one of the following protection levels:
public //(Default) Can be accessed inside and outside the class
protected //Can be accessed inside the class and any child class only (not outside the class)
private //Can be accessed inside the class only (not by a child class or outside the class)
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.