Share on Google+Share on Google+

PHP Object Type

Advertisement
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

Advertisements

Posted on: March 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.