Connect with us

PHP

PHP Class

mm

Published

on

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”;

Also Read :   PHP if...else

?>
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

}

 

Hi, Thank you for reading my article. I am Victor, a professional blogger from Jaipur, India.I started webetutorial for blogging & sharing solution for developer questions, and now it’s empowering globally by helping them to make money.I am writing about starting & managing a blogs, WordPress, Magento, Social Media, SEO, Marketing, making money online, Investment, Finance, Gadgets, Fitness and more.

Continue Reading
Advertisement
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

four × 3 =

Blog

PHP Magic Methods

mm

Published

on

  1. __get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically.
  2. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is set or not.
  3. __unset() – Similarly, when we call PHP unset() function on such dynamically created properties, this magic method will automatically be invoked.
  4. __call()/__callStatic() – These two magic methods are dedicated for accessing dynamically created but invisible methods on PHP method overloading.
  5. __sleep() – This will be invoked on calling PHP serialize() function.
  6. __wakeup() – It will do the reverse work to restore objects properties and resources.
  7. __toString() – This method is expected return a string value while using class instances with PHP printing statements.
  8. __invoke()-This method defined in a class will be called when we make a function call with the name of that class instance.
  9. __set_static()-This is a static method invoked while exporting objects property array and expects such array variable as its argument.
  10. __clone()-This function is used while PHP Object Cloning.
  11. __construct()/__destruct()

Also Read :   PHP Variables
Continue Reading

Trending