Protected Access Modifier in PHP

In this article I am going to explain about protected access modifier in PHP.
  • 1946

Introduction

When you declare the property and method with this keyword, you can access these methods and properties within the class, or/and the child class of that parent class can access these properties and methods of the parent class.

Example

<?php
class
Myclass
{

protected
$title=10;
}

class
Baseclass extends Myclass
{

function
__construct()
{

echo
$this->title;
}
}
$obj = new Baseclass();

?>

Output

Protected-access-modifier-in-php.jpg

© 2020 DotNetHeaven. All rights reserved.