Class property
In PHP, a class property is a variable that is defined within a class and is accessible to all instances (objects) of that class. It can hold various types of data such as strings, integers, arrays, or objects. Class properties can be declared with the “public”, “private”, or “protected” visibility modifiers to control their accessibility from within and outside the class.
To access a class property, you can use the object operator “->” followed by the property name. For example, if you have a class called “Person” with a property “name”, you can create an instance of the class and set the “name” property like this:
class Person { public $name; } $person = new Person(); $person->name = “John”;
You can also initialize class properties when declaring them, like this:
class Person { public $name = “John”; }
Class properties are useful for storing data that needs to be shared across multiple methods or instances of a class.
Apply for PHP Certification!
https://www.vskills.in/certification/certified-php-developer