Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Advance PHP

What was easy in any language was made core and what became difficult was made an advance. What happens in Core is of basic level and what happens in Advance is of upper-level.

Object Oriented Progrmming

Object-Oriented Programming is a Technic that solves the problem. In this, the code breaks the object. And you see your problem on the side of the object. In which you find your problem similar to the real-world problem and it is easy to maintain, and it has to be solved.

Class

The PHP class has a group of values. To manipulate whatever value you write inside the class, you also write operations in it. The class gives you this facility, that if the user does not need to know the information. So you can also hide the information. To use the application, you can keep it hidden for security purposes. Or if it will be accessed from the outside users or from an outside viewer then your application may be damaged. That’s why you can keep your application hidden, it gives class facility. You can define type using class.

Rule

  • The class name can be any valid label.
  • It can’t be PHP reserved world.
  • The class name must start with a letter or an underscore. Following by any number of letters, numbers, or underscore all this will work. Lwkin should not start with number.
class Classname
{
	var $variable_name;  (It is also called Data Member/Properties or Attribute.)
	var $variable_name;
	
	function Method_name()
	{
		Body of method;
	}
	function Method_name(parameter_list)     (And these methods are called methods or member functions.)
	{
		Body of Method;
	}

}

See your problem in the real world.

class Mobile
{
	public $model;
	function show Model (Sumber)
	{
		$this->model = $number;
		echo "Model Number: $this->model";
	}
	
}

Object

The object is a variable of class data type. Whenever you create an object, for that object, whatever is proper inside the class, a copy of it is prepared and it is prepared for that object. If there are 2 objects then 2 copies of that variable or that property will be created and one copy for the first object and a second copy for the second object. Whatever object you make, its copy will be ready and one copy will be distributed. But this is not the case with the member function. The member function is the same, all the objects share with it.

The new Operator is used to create an object.

Syntax:

class Mobile
{
	public $model;
	function show Model (Sumber)
	{
		$this->model = $number;
		echo "Model Number: $this->model";
	}
	
}
$samsung = new Mobile;
$samsung->showModel('A5');

$lg = new Mobile;
$lg->showModel('M30');

You will not need to write the class, again and again, you just have to create an object of it. And call this method with the help of that object. It will show its own model number.

Important thing

A class is of no importance unless it has an object.

Accessing class member using object

How would you make accessing a member of a class into a user object?

-> This operator is used to access the member of the class.

object_name->variable_name;
$samsung->model;

access to method
Object_name->method_name();
$samsung->showModel();

in parameter
Object_name->method_name(parameter_list)
$samsung->showModel(‘A8’);

Tagged : / / / /
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x