How you can use the abstract classes with PHP

Hi guys! In this tutorial I will explain how you can use the abstract classes with PHP.

I will create a simple abstract php class:

abstract class first{
abstract protected function info();
public function get()
{
print $this->info();
}
}

This class has an protected function and a public function. The procted function will get information and the public function will print it.

Now I will create a child class of the abstract class:

class newclass extends first
{
protected function info()
{
return "Hello World!";
}

}

The created class will return the function info with information "Hello World!".

Now, to display the results, I will write this code:

$newclass = new newclass();
$newclass->get(); // I call the public function

Video Tutorial:









Leave a Comment