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