Skip to content

Commit 97429ea

Browse files
bjoriderickr
authored andcommitted
PHPC-431: Add the testcase from the report
1 parent 46f6002 commit 97429ea

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
PHPC-431: Segfault when using Manager through singleton class
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
use MongoDB\Driver\Manager;
8+
use MongoDB\Driver\Query;
9+
use MongoDB\Driver\ReadPreference;
10+
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
13+
14+
class Database {
15+
private $Database;
16+
private static $Instance;
17+
18+
public function __construct() {
19+
$Manager = new Manager(STANDALONE, array(), array());
20+
$this->Database = $Manager;
21+
}
22+
23+
public static function getInstance() {
24+
if (static::$Instance == null) {
25+
static::$Instance = new Database();
26+
}
27+
28+
return static::$Instance;
29+
}
30+
31+
public function query($scheme, $query) {
32+
return $this->Database->executeQuery($scheme, $query, new ReadPreference(ReadPreference::RP_PRIMARY));
33+
}
34+
}
35+
36+
class App {
37+
public function run() {
38+
$db = Database::getInstance();
39+
40+
$query = new Query(array());
41+
$cursor = $db->query(DATABASE_NAME . ".scheme_info", $query);
42+
43+
foreach ($cursor as $document) {
44+
echo $document->value;
45+
}
46+
47+
$query = new Query(array());
48+
$cursor = $db->query(DATABASE_NAME . ".domain", $query);
49+
50+
foreach ($cursor as $document) {
51+
echo $document->hostname;
52+
}
53+
}
54+
}
55+
56+
$App = new App();
57+
$App->run();
58+
echo "All done\n";
59+
?>
60+
===DONE===
61+
<?php exit(0); ?>
62+
--EXPECT--
63+
All done
64+
===DONE===

0 commit comments

Comments
 (0)