Class & Object(php OOPS concept)

Posted by

OOPS ( Object Oriented Programming System)

Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a methodology  to design a program using classes and objects. It simplifies software development and maintenance by providing some concepts.

PHP(Hypertext preprocessor) Programming Patterns:

1)Procedural / Core PHP

2)Object Oriented (Object Oriented method is more popular then Core PHP )

OBJECT ORIENTED Advantage

  • Code more Modular and Reusable
  • Well Organized Code
  • Easier to debug
  • Best for medium to large website projects

Its MVC Frameworks are:-

Codeigniter, laravel, CakePHP, Symfony, Yii, Zend.

  What is Class?

A PHP class is a group of values with a set of operations to manipulate this values. Classes facilitate modularity and information hiding. Classes are used to define a new data type.

What is Object?

 Object is a compound data type,  Values of more than one types can be stored together in a single variable. Object is an instance of  user defined class.

Rules :

  • A variable starts with the $ sign, followed by the name of the variable.
  • A variable name must start with a letter or the underscore character.
  • A variable name cannot start with a number.
  • It can’t be PHP reserved word.
  • You can’t assign computed value inside a class. ($a = 12+5; )
  • You can’t concatenate in the class.(public $name=”ravi”.”Kumar”;)

Example:-

https://gist.github.com/AvinashKumar33/504957d7954d855c3f86134af10c3915

OUTPUT:-

fun1

Example;-

https://gist.github.com/AvinashKumar33/ef54d82d290a3e705635cfacc5173b6a

OUTPUT:-

Employee Detail

Name : ram
Age : 25
Salary : 20000

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x