Thursday, May 17

Object-Oriented Programming Concepts in PHP - Class & Object

Object-Oriented Programming Concepts in PHP

  • Class
  • Objects
  • Inheritance
  • Interface
  • Abstraction
  • Polymorphism

Class:

  • Class is a programmer-defined data type or Blue print of object.
  • Class definitions begin with the keyword class
  • A class may contain its own constants, variables (called "properties"), and functions (called "methods").
  • Class is a collection of objects. Object has properties and behavior.
  • A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

Example:
<?PHP // Class declaration class firstclass{ // property declaration public $var = 'Hello World'; // method declaration public function displayVar() { echo $this->var; } } $objfirst = new firstclass; $objfirst->displayVar(); ?> OUTPUT: Hello World Creating Objects
  • When class is created, we can create any number of objects to that class.
  • It simply known as class properties and methods operate on data are bundled as a unit called as object.
This

  • $this is available when a method is called from within an object context. Pointing the current object.
New

  • create an instance of a class, the new keyword must be used. An object will always be created unless the object has a constructor defined that throws an exception on error. 

No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...