summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-01-14 09:17:28 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-01-14 09:19:30 +0100
commitd0fd2be64234d978e62fb27d6012087514550e71 (patch)
tree8788eaaa9f2d36b512cc9cccb255e429bc30db48
parente25e2bd9bd0b878caf5fe80f6b53c7d42657ebd1 (diff)
downloadphp-git-d0fd2be64234d978e62fb27d6012087514550e71.tar.gz
Revert removal of private __clone() methods
I thought these were redundant, because we already NULL out the clone_obj object handler. However, it turns out that reflection is using private __clone() to determine clonability (isCloneable) for the case where we only have a class, rather than an object. As such, removing these methods would be a BC break. This reverts commit e7131a4e9fa0acf8fc1e486b49851e71859ef5b8. This reverts commit 55bd88ce0d1bf461546d5d0b40920491d566ed48.
-rw-r--r--Zend/zend_exceptions.c10
-rw-r--r--ext/reflection/php_reflection.c16
-rw-r--r--ext/reflection/tests/ReflectionClass_toString_001.phpt8
-rw-r--r--sapi/cli/tests/005.phpt11
4 files changed, 40 insertions, 5 deletions
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index 848e15b855..8330aba632 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -251,6 +251,15 @@ static zend_object *zend_error_exception_new(zend_class_entry *class_type) /* {{
}
/* }}} */
+/* {{{ proto Exception|Error Exception|Error::__clone()
+ Clone the exception object */
+ZEND_COLD ZEND_METHOD(exception, __clone)
+{
+ /* Should never be executable */
+ zend_throw_exception(NULL, "Cannot clone object using __clone()", 0);
+}
+/* }}} */
+
/* {{{ proto Exception|Error::__construct(string message, int code [, Throwable previous])
Exception constructor */
ZEND_METHOD(exception, __construct)
@@ -763,6 +772,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_exception___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry default_exception_functions[] = {
+ ZEND_ME(exception, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(exception, __construct, arginfo_exception___construct, ZEND_ACC_PUBLIC)
ZEND_ME(exception, __wakeup, NULL, ZEND_ACC_PUBLIC)
ZEND_ME(exception, getMessage, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 323a4d2fa4..d228a4b4d7 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -1407,6 +1407,14 @@ static zend_op *_reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAMETERS
}
/* }}} */
+/* {{{ Preventing __clone from being called */
+ZEND_METHOD(reflection, __clone)
+{
+ /* Should never be executable */
+ _DO_THROW("Cannot clone object using __clone()");
+}
+/* }}} */
+
/* {{{ proto public static mixed Reflection::export(Reflector r [, bool return])
Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
ZEND_METHOD(reflection, export)
@@ -6194,6 +6202,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_function_invokeArgs, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_function_abstract_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_function, inNamespace, arginfo_reflection__void, 0)
ZEND_ME(reflection_function, isClosure, arginfo_reflection__void, 0)
ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0)
@@ -6379,6 +6388,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_implementsInterface, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_class_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_class, export, arginfo_reflection_class_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_class, __construct, arginfo_reflection_class___construct, 0)
ZEND_ME(reflection_class, __toString, arginfo_reflection__void, 0)
@@ -6481,6 +6491,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_property_setAccessible, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_property_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_property, export, arginfo_reflection_property_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_property, __construct, arginfo_reflection_property___construct, 0)
ZEND_ME(reflection_property, __toString, arginfo_reflection__void, 0)
@@ -6514,6 +6525,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_constant___construct, 0, 0, 2)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_class_constant_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_class_constant, export, arginfo_reflection_class_constant_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_class_constant, __construct, arginfo_reflection_class_constant___construct, 0)
ZEND_ME(reflection_class_constant, __toString, arginfo_reflection__void, 0)
@@ -6540,6 +6552,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_parameter___construct, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_parameter_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_parameter, export, arginfo_reflection_parameter_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_parameter, __construct, arginfo_reflection_parameter___construct, 0)
ZEND_ME(reflection_parameter, __toString, arginfo_reflection__void, 0)
@@ -6565,6 +6578,7 @@ static const zend_function_entry reflection_parameter_functions[] = {
};
static const zend_function_entry reflection_type_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_type, allowsNull, arginfo_reflection__void, 0)
ZEND_ME(reflection_type, isBuiltin, arginfo_reflection__void, 0)
/* ReflectionType::__toString() is deprecated, but we currently do not mark it as such
@@ -6589,6 +6603,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_extension___construct, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_extension_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_extension, __construct, arginfo_reflection_extension___construct, 0)
ZEND_ME(reflection_extension, __toString, arginfo_reflection__void, 0)
@@ -6611,6 +6626,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_zend_extension___construct, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry reflection_zend_extension_functions[] = {
+ ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
ZEND_ME(reflection_zend_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_zend_extension, __construct, arginfo_reflection_zend_extension___construct, 0)
ZEND_ME(reflection_zend_extension, __toString, arginfo_reflection__void, 0)
diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt
index 474d663888..e97af14110 100644
--- a/ext/reflection/tests/ReflectionClass_toString_001.phpt
+++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt
@@ -34,7 +34,13 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] {
Property [ <default> public $name ]
}
- - Methods [52] {
+ - Methods [53] {
+ Method [ <internal:Reflection> final private method __clone ] {
+
+ - Parameters [0] {
+ }
+ }
+
Method [ <internal:Reflection, ctor> public method __construct ] {
- Parameters [1] {
diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt
index f02014a304..0a366b6975 100644
--- a/sapi/cli/tests/005.phpt
+++ b/sapi/cli/tests/005.phpt
@@ -15,10 +15,10 @@ var_dump(`"$php" -n --rc exception`);
echo "Done\n";
?>
---EXPECTF--
+--EXPECT--
string(40) "Exception: Class unknown does not exist
"
-string(%d) "Class [ <internal:Core> class stdClass ] {
+string(183) "Class [ <internal:Core> class stdClass ] {
- Constants [0] {
}
@@ -37,7 +37,7 @@ string(%d) "Class [ <internal:Core> class stdClass ] {
}
"
-string(%d) "Class [ <internal:Core> class Exception implements Throwable ] {
+string(1607) "Class [ <internal:Core> class Exception implements Throwable ] {
- Constants [0] {
}
@@ -58,7 +58,10 @@ string(%d) "Class [ <internal:Core> class Exception implements Throwable ] {
Property [ <default> private $previous ]
}
- - Methods [10] {
+ - Methods [11] {
+ Method [ <internal:Core> final private method __clone ] {
+ }
+
Method [ <internal:Core, ctor> public method __construct ] {
- Parameters [3] {