Posted By

ekobudisetiyo on 07/10/06


Tagged

object open php5


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

tylerhall
postNuKe
vaaaska


Open PHP5 Object, No need to declare variable name first


 / Published in: PHP
 

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

  1. //PHP5 only//
  2.  
  3. class open
  4. {
  5. var $____x = array();
  6. function __construct($a = array())
  7. {
  8. $this->fromArray($a);
  9. }
  10.  
  11. function __set($name,$val)
  12. {
  13. $this->____x[$name] = $val;
  14. }
  15.  
  16. function __get($name)
  17. {
  18. if(isset($this->____x[$name])) return $this->____x[$name];
  19. }
  20.  
  21. function __isset($name)
  22. {
  23. return isset($this->____x[$name]);
  24. }
  25.  
  26. function toArray()
  27. {
  28. return $this->____x;
  29. }
  30.  
  31. function fromArray($a = array())
  32. {
  33. if(count($a)>0) foreach($a as $k => $v) $this->____x[$k] = $v;
  34. }
  35.  
  36. }

Report this snippet  

You need to login to post a comment.