Skip to content

Commit 65b4f22

Browse files
Fix some misleading comments about __clone() never being executed (#15926)
For the `Exception`, `ReflectionClass`, and `ReflectionAttribute` classes, the `__clone()` method is declared to be private, and the implementation has a comment that it should never be executed. However, the implementation can be executed by using a `ReflectionMethod`. Fix the comments to instead explain why the implementation is needed. [skip ci]
1 parent 2fce0bb commit 65b4f22

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Zend/zend_exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static zend_object *zend_default_exception_new(zend_class_entry *class_type) /*
295295
/* {{{ Clone the exception object */
296296
ZEND_COLD ZEND_METHOD(Exception, __clone)
297297
{
298-
/* Should never be executable */
298+
/* __clone() is private but this is reachable with reflection */
299299
zend_throw_exception(NULL, "Cannot clone object using __clone()", 0);
300300
}
301301
/* }}} */

ext/reflection/php_reflection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ static int get_parameter_default(zval *result, parameter_reference *param) {
15731573
/* {{{ Preventing __clone from being called */
15741574
ZEND_METHOD(ReflectionClass, __clone)
15751575
{
1576-
/* Should never be executable */
1576+
/* __clone() is private but this is reachable with reflection */
15771577
_DO_THROW("Cannot clone object using __clone()");
15781578
}
15791579
/* }}} */
@@ -7183,7 +7183,7 @@ ZEND_METHOD(ReflectionAttribute, __construct)
71837183

71847184
ZEND_METHOD(ReflectionAttribute, __clone)
71857185
{
7186-
/* Should never be executable */
7186+
/* __clone() is private but this is reachable with reflection */
71877187
_DO_THROW("Cannot clone object using __clone()");
71887188
}
71897189

0 commit comments

Comments
 (0)