PHP Class Object

PHP Class Object
PHP Class Object

What is Class?

Class is a collection of related method & Properties.

NOTE: Function is known as method while variable is known as properties.

How to define a class

Class always start with “class” keyword. After this write class name without parentheses.

Syntax:

Example:

 

What is Object:

  • Object is the instance of the class.
  • Once a class has been defined, objects can be created from the class through “new” keyword.
  • class methods and properties can directly be accessed through this object instance.
  • Connector(Dot operator->) symbol used to connect objects to their properties or methods.

Note: You can not access any property of the class without their object>

Syntax:

Example:

Output:

Create dynamic program using oops(Numbers entered by user)

Output:

Leave a Reply

Your email address will not be published.