From a50adda19e69aeef9fb5cb3536fdeb305178efc3 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 28 Jul 2024 13:03:26 +0100 Subject: [PATCH] ext/gmp: Make GMP class final (#15121) * ext/gmp: Make GMP class final RFC: https://wiki.php.net/rfc/gmp-final * Update UPGRADING Co-authored-by: Peter Kokot --------- Co-authored-by: Peter Kokot --- NEWS | 3 +++ UPGRADING | 4 ++++ ext/gmp/gmp.stub.php | 2 +- ext/gmp/gmp_arginfo.h | 3 ++- ext/gmp/tests/final.phpt | 12 ++++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 ext/gmp/tests/final.phpt diff --git a/NEWS b/NEWS index b9753c06aa1..147d6ce70f5 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,9 @@ PHP NEWS . /dev/poll events.mechanism for Solaris/Illumos setting had been retired. (David Carlier) +- GMP: + . The GMP class is now final and cannot be extended anymore. + - Intl: . Added SpoofChecker::setAllowedChars to set unicode chars ranges. (David Carlier) diff --git a/UPGRADING b/UPGRADING index 4974182f4d4..0fe03244ab1 100644 --- a/UPGRADING +++ b/UPGRADING @@ -48,6 +48,10 @@ PHP 8.4 UPGRADE NOTES object. This is no longer possible, and cloning a DOMXPath object now throws an error. +- GMP: + . The GMP class is now final and cannot be extended anymore. + RFC: https://wiki.php.net/rfc/gmp-final + - Intl: . resourcebundle_get(), ResourceBundle::get(), and accessing offsets on a ResourceBundle object now throw: diff --git a/ext/gmp/gmp.stub.php b/ext/gmp/gmp.stub.php index ff5b5afb405..75812c62c5c 100644 --- a/ext/gmp/gmp.stub.php +++ b/ext/gmp/gmp.stub.php @@ -57,7 +57,7 @@ const GMP_BIG_ENDIAN = UNKNOWN; */ const GMP_NATIVE_ENDIAN = UNKNOWN; -class GMP +final class GMP { public function __construct(int|string $num = 0, int $base = 0) {} diff --git a/ext/gmp/gmp_arginfo.h b/ext/gmp/gmp_arginfo.h index 8126fa66867..43d69440368 100644 --- a/ext/gmp/gmp_arginfo.h +++ b/ext/gmp/gmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d52f82c7084a8122fe07c91eb6d4ab6030daa27d */ + * Stub hash: 3aabd5a5d2db0df15b249a425465ae718c13ab6b */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_init, 0, 1, GMP, 0) ZEND_ARG_TYPE_MASK(0, num, MAY_BE_LONG|MAY_BE_STRING, NULL) @@ -334,6 +334,7 @@ static zend_class_entry *register_class_GMP(void) INIT_CLASS_ENTRY(ce, "GMP", class_GMP_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); + class_entry->ce_flags |= ZEND_ACC_FINAL; return class_entry; } diff --git a/ext/gmp/tests/final.phpt b/ext/gmp/tests/final.phpt new file mode 100644 index 00000000000..1bc485ac6e1 --- /dev/null +++ b/ext/gmp/tests/final.phpt @@ -0,0 +1,12 @@ +--TEST-- +Cannot extend GMP class +--EXTENSIONS-- +gmp +--FILE-- + +--EXPECTF-- +Fatal error: Class T cannot extend final class GMP in %s on line %d