Example
Use public to declare a property that can be modified by any code:
html
<?php
class MyClass {
public $number = 0;
}
$obj = new MyClass();
$obj->number = 5;
echo "The number is " . $obj->number;
?>
Definition and Usage
The public keyword is an access modifier. It marks a property or method as public.
Public properties and methods can be used by any code that can access the object.
Related Pages
The protected keyword
The private keyword