bug32322.phpt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. Bug #32322 (Return values by reference broken( using self::),example singleton instance)
  3. --INI--
  4. error_reporting=4095
  5. --FILE--
  6. <?php
  7. class test
  8. {
  9. private static $instance = null;
  10. private $myname = '';
  11. private function __construct( $value = '' )
  12. {
  13. echo "New class $value created \n";
  14. $this -> myname = $value;
  15. }
  16. private function __clone() {}
  17. static public function getInstance()
  18. {
  19. if ( self::$instance == null )
  20. {
  21. self::$instance = new test('Singleton1');
  22. }
  23. else {
  24. echo "Using old class " . self::$instance -> myname . "\n";
  25. }
  26. return self::$instance;
  27. }
  28. static public function getInstance2()
  29. {
  30. static $instance2 = null;
  31. if ( $instance2 == null )
  32. {
  33. $instance2 = new test('Singleton2');
  34. }
  35. else {
  36. echo "Using old class " . $instance2 -> myname . "\n";
  37. }
  38. return $instance2;
  39. }
  40. public function __destruct()
  41. {
  42. if ( defined('SCRIPT_END') )
  43. {
  44. echo "Class " . $this -> myname . " destroyed at script end\n";
  45. } else {
  46. echo "Class " . $this -> myname . " destroyed beforce script end\n";
  47. }
  48. }
  49. }
  50. echo "Try static instance inside class :\n";
  51. $getCopyofSingleton = test::getInstance();
  52. $getCopyofSingleton = null;
  53. $getCopyofSingleton = &test::getInstance();
  54. $getCopyofSingleton = null;
  55. $getCopyofSingleton = test::getInstance();
  56. echo "Try static instance inside function :\n";
  57. $getCopyofSingleton2 = test::getInstance2();
  58. $getCopyofSingleton2 = null;
  59. $getCopyofSingleton2 = &test::getInstance2();
  60. $getCopyofSingleton2 = null;
  61. $getCopyofSingleton2 = test::getInstance2();
  62. define('SCRIPT_END',1);
  63. ?>
  64. --EXPECTF--
  65. Try static instance inside class :
  66. New class Singleton1 created
  67. Using old class Singleton1
  68. Notice: Only variables should be assigned by reference in %sbug32322.php on line 49
  69. Using old class Singleton1
  70. Try static instance inside function :
  71. New class Singleton2 created
  72. Using old class Singleton2
  73. Notice: Only variables should be assigned by reference in %sbug32322.php on line 55
  74. Using old class Singleton2
  75. Class Singleton1 destroyed at script end
  76. Class Singleton2 destroyed at script end