In this article, you will learn about private keyword in PHP. The private keyword in PHP is an access modifier. It marks a property or method as private.
Private methods and properties are accessible only within the class.
examples of the PRIVATE function
Example 1. In this example, we use private to prevent outside code or derived classes from modifying a property.
<?php
class MyClass {
private $number = 0;
public function add1() {
$this->number++;
}
public function getNumber() {
return $this->number;
}
}
$obj = new MyClass();
$obj->add1();
echo "The number is " . $obj->getNumber();
?>