Concept for Object Oriented Language

  1. Object-Oriented:- With Object-Oriented Programming, we could copy the general idea by using a class.
  2. Class:- A class is a unit of code that explains the characteristics and behaviors.
  3. Object:- An object is a explicit instance of a class.
  4. Properties:- The characteristics of a class or object are known as its properties.
  5. Method:- The behaviors of a class are known as its methods.

 
PHP Class
In PHP we use class keyword to define a class.

Syntax:-

<?php

Class ClassName

{

//properties

//methods

}

?>
PHP Class Object
A class is defining or creating a new type.

Syntax: –

$classObject = new objectClass;

And we need to use the special -> operator to reference the method

<?PHP

Class ClassName

{

public function sa()

{

print “data”;

}

}

$classobject = new Sa;

$classobject->sa();

?>
Objects Within Objects
Syntax:-

<?PHP

class Nameblog

{

public $Words;

}

class website

{

public $Name;

public $Nameblog;

public function sa()

{

print “website”;

}

}

$booclass = new Boo;

$booclass->Name = “PHP”;

$booclass->Nameblog = new Nameblog;

$booclass->Nameblog->Words = “from webetutorial”;

?>
PHP Class Properties
Class properties are very related to variables. An object property could store a single value, an array of values. To add a property to a class belongs with the keyword public, private, or protected.

Syntax:-

Class ClassName

{

public $property1;

// This is a public property

private $property2;

// This is a private property

protected $property3;

// This is a protected property

}

 

Categories: PHP

0 thoughts on “PHP Class”

Leave a Reply

Latest Article

Blog

PHP Magic Methods

__get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is Read more…

Blog

WordPress Upgrade

The WordPress upgrade released time to time. We provide a WordPress upgrade, content management and maintenance services at affordable price. WordPress upgrade fixes bugs, runs cleaner, faster, and is more secure and stable. We will Read more…

Blog

Magento 2 Upload image in product

If you are trying to upload image on respective product by script then below code will help you to solve this issue. by this code you can set product thumbnail, small and large image. $objectManager Read more…