PHP5 Constant Class


/ Published in: PHP
Save to your folder(s)

Usage:

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


Copy this code and paste it in your HTML
  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. ?>

URL: http://fuselogic.haltebis.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.