Return to Snippet

Revision: 337
at July 12, 2006 05:37 by ekobudisetiyo


Updated Code
//PHP5 only//

class open
{
   var $____x = array();
   function __construct($a = array())
   {
      $this->fromArray($a);
   }

   function __set($name,$val)
   {
      $this->____x[$name] = $val;
   }

   function __get($name)
   {
       if(isset($this->____x[$name])) return $this->____x[$name];
   }

   function __isset($name)
   {
      return isset($this->____x[$name]);
   }

   function toArray()
   {
      return $this->____x;
   }

   function fromArray($a = array())
   {
      if(count($a)>0) foreach($a as $k => $v) $this->____x[$k] = $v;
   }

}

Revision: 336
at July 10, 2006 03:05 by ekobudisetiyo


Initial Code
//PHP5 only//

class open
{
   var $____x = array();
   function __construct($a = array())
   {
      $this->fromArray($a);
   }

   function __set($name,$val)
   {
      $this->____x[$name] = $val;
   }

   function __get($name)
   {
       if(isset($this->____x[$name])) return $this->____x[$name];
   }

   function __isset($name)
   {
      return isset($this->____x[$name]);
   }

   function toArray()
   {
      return $this->____x;
   }

   function fromArray($a = array())
   {
      if(count($a)>0) foreach($a as $k => $v) $this->____x[$k] = $v;
   }

}
?>

Initial URL

                                

Initial Description
I use this object verry often, so that I only need to pass one object as parameter on any function. No need to wory when we refactore the function
Usage: 
$var = new open();
$var->url = 'http://www.world.com';
$var->title = 'Testing Site';

echo some_function($var);

Initial Title
Open PHP5 Object, No need to declare variable name first

Initial Tags
object

Initial Language
PHP