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