Share on Google+Share on Google+

PHP set static Method

In this current tutorial we will study about a new method called __set_static(), which is introduced in PHP 5. With the help of this method we can assign values to a new object dynamically. Examples will help to understand the concept

_set_static()Method in PHP :

In this tutorial we will study how to assign values of an object to another object dynamically. To do this we use __set_static() method.

We need to declare a magic method called __set_static() which is declared inside the class and by using var_export() we pass a values to it and assign the values to locally declared an object and after assigning the values we return the object.

PHP Set Static Method Example:


class A


public $var1;

public $var2;

public static function __set_state($array)


$obj2=new A;



return $obj2;



$obj1=new A;







object(A)#2 (2) { ["var1"]=> int(2010) ["var2"]=> string(4) "year" }



Posted on: March 4, 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.


Advertisement null