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;
?>