Skip to content

Commit 0357824

Browse files
committed
PHPC-155: WriteConcernError->getInfo() can be scalar
1 parent 9051914 commit 0357824

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/MongoDB/WriteConcernError.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ PHP_METHOD(WriteConcernError, getCode)
6767
RETURN_LONG(intern->code);
6868
}
6969
/* }}} */
70-
/* {{{ proto array WriteConcernError::getInfo()
70+
/* {{{ proto mixed WriteConcernError::getInfo()
7171
Returns additional metadata for the error */
7272
PHP_METHOD(WriteConcernError, getInfo)
7373
{
7474
php_phongo_writeconcernerror_t *intern;
75-
zend_error_handling error_handling;
75+
zend_error_handling error_handling;
7676

7777

7878
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
@@ -85,11 +85,9 @@ PHP_METHOD(WriteConcernError, getInfo)
8585
zend_restore_error_handling(&error_handling TSRMLS_CC);
8686

8787

88-
if (intern->info && Z_TYPE_P(intern->info) == IS_ARRAY) {
88+
if (intern->info) {
8989
RETURN_ZVAL(intern->info, 1, 0);
9090
}
91-
92-
array_init(return_value);
9391
}
9492
/* }}} */
9593
/* {{{ proto string WriteConcernError::getMessage()
@@ -183,8 +181,12 @@ HashTable *php_phongo_writeconcernerror_get_debug_info(zval *object, int *is_tem
183181
array_init_size(&retval, 3);
184182
add_assoc_string_ex(&retval, ZEND_STRS("message"), intern->message, 1);
185183
add_assoc_long_ex(&retval, ZEND_STRS("code"), intern->code);
186-
Z_ADDREF_P(intern->info);
187-
add_assoc_zval_ex(&retval, ZEND_STRS("info"), intern->info);
184+
if (intern->info) {
185+
Z_ADDREF_P(intern->info);
186+
add_assoc_zval_ex(&retval, ZEND_STRS("info"), intern->info);
187+
} else {
188+
add_assoc_null_ex(&retval, ZEND_STRS("info"));
189+
}
188190

189191
return Z_ARRVAL(retval);
190192
} /* }}} */

tests/replicaset/bug0155.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
MongoDB\Driver\WriteConcern construction
3+
--SKIPIF--
4+
<?php require "tests/utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once "tests/utils/basic.inc";
8+
9+
$manager = new MongoDB\Driver\Manager(MONGODB_REPLICASET_URI);
10+
11+
12+
$wc = new MongoDB\Driver\WriteConcern("MultipleDC", 500);
13+
14+
$doc = array("example" => "document");
15+
try {
16+
$result = $manager->executeInsert("databaseName.collectionName", $doc, $wc);
17+
} catch(MongoDB\Driver\Exception $e) {
18+
var_dump(get_class($e), $e->getMessage());
19+
}
20+
var_dump($result->getWriteConcernError());
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECTF--
25+
object(MongoDB\Driver\WriteConcernError)#%d (%d) {
26+
["message"]=>
27+
string(%d) "%s"
28+
["code"]=>
29+
int(79)
30+
["info"]=>
31+
NULL
32+
}
33+
===DONE===

0 commit comments

Comments
 (0)