Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/temporary_cleaning_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gmp
<?php
set_error_handler(function() { throw new Exception; });
try {
new GMP ?: null;
gmp_init(0) ?: null;
} catch (Exception $e) {
}
?>
Expand Down
7 changes: 7 additions & 0 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ static inline void gmp_create(zval *target, mpz_ptr *gmpnum_target) /* {{{ */
}
/* }}} */

static zend_function *gmp_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "Cannot directly construct GMP, use gmp_init() instead");
return NULL;
}

static int gmp_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */
{
mpz_ptr gmpnum;
Expand Down Expand Up @@ -534,6 +540,7 @@ ZEND_MINIT_FUNCTION(gmp)
memcpy(&gmp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
gmp_object_handlers.offset = XtOffsetOf(gmp_object, std);
gmp_object_handlers.free_obj = gmp_free_object_storage;
gmp_object_handlers.get_constructor = gmp_get_constructor;
gmp_object_handlers.cast_object = gmp_cast_object;
gmp_object_handlers.get_debug_info = gmp_get_debug_info;
gmp_object_handlers.clone_obj = gmp_clone_obj;
Expand Down
14 changes: 14 additions & 0 deletions ext/gmp/tests/bug-gh10155.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GMP constructor should not be called directly
--EXTENSIONS--
gmp
--FILE--
<?php
try {
var_dump(new GMP(6));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot directly construct GMP, use gmp_init() instead