PHP WITH OOPS CONCEPT

Object-oriented programming is a programming model organized around Object rather than the actions and data rather than logic.

Class:

A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object.

In PHP, declare a class using the class keyword, followed by the name of the class and a set of curly braces ({}).

PHP WITH OOPS CONCEPT

This is the blueprint of the construction work that is class, and the houses and apartments made by this blueprint are the objects.

Syntax to Create Class in PHP

snippet
<?php
class MyClass
	{
		// Class properties and methods go here
	}
?>

Important note:

In PHP, to see the contents of the class, use var_dump(). The var_dump() function is used to display the structured information (type and value) about one or more variables.

Syntax:

snippet
var_dump($obj);

Object:

A class defines an individual instance of the data structure. We define a class once and then make many objects that belong to it. Objects are also known as an instance.

An object is something that can perform a set of related activities.

Syntax:

snippet
<?php
class MyClass
{
		// Class properties and methods go here
}
$obj = new MyClass;
var_dump($obj);
?>

Example of class and object:

snippet
<?php
class demo
{
		private $a= "hello rookienerd";
		public function display()
		{
		echo $this->a;
		}
}
$obj = new demo();
	$obj->display();
?>

Output:

PHP WITH OOPS CONCEPT

Example 2: Use of var_dump($obj);

snippet
<?php
class demo
{
		private $a= "hello rookienerd";
		public function display()
		{
		echo $this->a;
		}
}
$obj = new demo();
	$obj->display();
	var_dump($obj);
?>

Output:

PHP WITH OOPS CONCEPT
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +