Posted By

ekobudisetiyo on 10/03/06


Tagged

php5 constant


Versions (?)

PHP5 Constant Class


 / Published in: PHP
 

URL: http://fuselogic.haltebis.com

Usage:

$constant = new constant(); $constant->test = 'abcd'; $constant->test = '1234'; echo $constant->test; // out put -> 'abcd'

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

Report this snippet  

You need to login to post a comment.