PHP Class Object - learning html - Phptpoint.com

PHP Class Object

/ins>

Object and Class in PHP

  • Class is a blueprint of related data members(proerties/variable) and methods(function).
  • Classes are the fundamental construct behind oops.
  • Class is a self contained independent collection of variables and functions, which work together to perform one or more specific related task.

Note: Variables within a class are called properties and functions are called methods

How to define a class

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

Syntax

Eg


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

Eg

Output
Sum=1000
Subtraction=500

Ex ii

Output
welcome users

Using Parametrized method

Output
Sum=1000
Subtraction=500

Create dynamic program using oops(Numbers entered by user)

Output
Sum=1500
Subtraction=500
Enter first number
Enter second number