Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 1.47 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Unexpected T_PAAMAYIM_NEKUDOTAYIM in PHP 5.2.x
  2. class xpto
  3. {
  4.     public static $id = null;
  5.  
  6.     public function __construct()
  7.     {
  8.     }
  9.  
  10.     public static function getMyID()
  11.     {
  12.         return self::$id;
  13.     }
  14. }
  15.  
  16. function instance($xpto = null)
  17. {
  18.     static $result = null;
  19.  
  20.     if (is_null($result) === true)
  21.     {
  22.         $result = new xpto();
  23.     }
  24.  
  25.     if (is_object($result) === true)
  26.     {
  27.         $result::$id = strval($xpto);
  28.     }
  29.  
  30.     return $result;
  31. }
  32.        
  33. echo var_dump(instance()->getMyID()) . "n"; // null
  34. echo var_dump(instance('dev')->getMyID()) . "n"; // dev
  35. echo var_dump(instance('prod')->getMyID()) . "n"; // prod
  36. echo var_dump(instance()->getMyID()) . "n"; // null
  37.        
  38. if (is_object($result) === true)
  39. {
  40.     $result::id = strval($xpto);
  41. }
  42.        
  43. if (is_object($result) === true)
  44. {
  45.     $result::$id = strval($xpto);
  46. }
  47.        
  48. function instance($xpto = null)
  49. {
  50.     static $result = null;
  51.  
  52.     if (is_null($result) === true)
  53.     {
  54.         $result = new xpto();
  55.     }
  56.  
  57.     if (is_object($result) === true)
  58.     {
  59.         xpto::$id = strval($xpto)
  60.     }
  61.  
  62.     return $result;
  63. }
  64.        
  65. $class = new ReflectionClass($xpto);
  66. echo $class->setStaticPropertyValue ('id', strval($xpto));
  67.        
  68. class Sample{
  69.     public static $name;
  70.  
  71.     public function __construct(){
  72.         self::$name = "User 1";
  73.     }
  74. }
  75.  
  76. $sample = new Sample();
  77. $class = 'Sample';
  78. $name = 'name';
  79. $val_name = "";
  80. $str = '$class::$$name';
  81. eval("$val_name = "$str";");
  82. //echo $val_name."<br>";
  83. eval("$name = $val_name;");
  84. echo $name;