bug53748.phpt 778 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Bug #53748 (Using traits lead to a segmentation fault)
  3. --FILE--
  4. <?php
  5. trait Singleton {
  6. protected static $instances=array();
  7. abstract protected function __construct($config);
  8. public static function getInstance($config) {
  9. if (!isset(self::$instances[$serialize = serialize($config)])) {
  10. self::$instances[$serialize] = new self($config);
  11. }
  12. return self::$instances[$serialize];
  13. }
  14. }
  15. class MyHelloWorld {
  16. use Singleton;
  17. public function __construct($config)
  18. {
  19. var_dump( $config);
  20. }
  21. }
  22. $o= myHelloWorld::getInstance(1);
  23. $o= myHelloWorld::getInstance(1);
  24. $o= myHelloWorld::getInstance(2);
  25. $o= myHelloWorld::getInstance(array(1=>2));
  26. $o= myHelloWorld::getInstance(array(1=>2));
  27. ?>
  28. --EXPECT--
  29. int(1)
  30. int(2)
  31. array(1) {
  32. [1]=>
  33. int(2)
  34. }