PHP Object Type


 

PHP Object Type

This PHP tutorial will reveal some interesting concepts of object, in addition it gives you a glimpse on object in PHP.

This PHP tutorial will reveal some interesting concepts of object, in addition it gives you a glimpse on object in PHP.

PHP Object:

Class, and Object are one of the most important feature of OOP. Object is the instance of a class, to create an object we use new keyword.

In PHP we can convert any value to an object of a predefined class called stdClass. The value of any variable is stored in a member variable of the class (stdClass) called scalar.

Note: In the following examples there is no closing tag is included, since it is optional to add the end tag when no html coding is embedded.

PHP Object Example:

<?php

class A

{

private $a=12;

public function display()

{

echo $this->a;

}

}

$obj=new A();

$obj->display();

 

Output:

12

Example:

<?php

$obj=(object)34;

echo $obj->scalar;

 

Output:

34

Ads