PHP public Keyword

P
PHP require Keyword
PHP protected Keyword

In this article, you will learn about the public keyword in PHP. The public keyword in PHP is an access modifier. It marks a property or method as public.

The public methods and properties are accessible both within and outside the class.

examples of the PUBLIC function

Example 1. In this example, we use the public to declare a property that can be modified by any code.

<?php
class MyClass {
  public $number = 0;
}

$obj = new MyClass();
$obj->number = 5;
echo "The number is " . $obj->number;
?>
PHP require Keyword
PHP protected Keyword

Tutor Network

Share this

Learn PHP from A to Z