PHP private Keyword

PHP protected Keyword
PHP print Keyword

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.

class MyClass {
  private $number = 0;

  public function add1() {

  public function getNumber() {
    return $this->number;

$obj = new MyClass();
echo "The number is " . $obj->getNumber();
PHP protected Keyword
PHP print Keyword
en English
Scroll to Top