Skip to content

Commit da08246

Browse files
committed
Address some review concerns
Still missing preventing userland classes from applying the attribute
1 parent ba04525 commit da08246

7 files changed

Lines changed: 28 additions & 22 deletions

File tree

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ PHP NEWS
126126
- PGSQL:
127127
. Enabled 64 bits support for pg_lo_truncate()/pg_lo_tell()
128128
if the server supports it. (KentarouTakeda)
129-
. pg_fetch_object() now surfaces non-instantiable class errorsv before
129+
. pg_fetch_object() now surfaces non-instantiable class errors before
130130
fetching, and reports the empty-constructor ValueError on the
131131
$constructor_args argument. (David Carlier)
132132

UPGRADING

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ PHP 8.6 UPGRADE NOTES
8686
. posix_mkfifo() now raises a ValueError when an invalid $permissions
8787
argument value is passed.
8888

89-
- Reflection:
90-
. ReflectionClass::newInstanceWithoutConstructor() no longer accepts
91-
classes with non-public constructors.
92-
9389
- Session:
9490
. Setting session.cookie_path, session.cookie_domain, or session.cache_limiter
9591
to a value containing null bytes now emits a warning and leaves the setting

Zend/zend_API.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,13 +1790,17 @@ ZEND_API void object_properties_load(zend_object *object, const HashTable *prope
17901790
* class and all props being public. If only a subset is given or the class
17911791
* has protected members then you need to merge the properties separately by
17921792
* calling zend_merge_properties(). */
1793-
static zend_always_inline zend_result _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties) /* {{{ */
1793+
static zend_always_inline zend_result _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties, bool known_instantiable) /* {{{ */
17941794
{
1795-
if (UNEXPECTED(class_type->ce_flags & ZEND_ACC_UNINSTANTIABLE)) {
1796-
zend_cannot_instantiate_class(class_type, NULL);
1797-
ZVAL_NULL(arg);
1798-
Z_OBJ_P(arg) = NULL;
1799-
return FAILURE;
1795+
if (!known_instantiable) {
1796+
if (UNEXPECTED(class_type->ce_flags & ZEND_ACC_UNINSTANTIABLE)) {
1797+
zend_cannot_instantiate_class(class_type, NULL);
1798+
ZVAL_NULL(arg);
1799+
Z_OBJ_P(arg) = NULL;
1800+
return FAILURE;
1801+
}
1802+
} else {
1803+
ZEND_ASSERT((class_type->ce_flags & ZEND_ACC_UNINSTANTIABLE) == 0);
18001804
}
18011805

18021806
if (UNEXPECTED(!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
@@ -1825,24 +1829,29 @@ static zend_always_inline zend_result _object_and_properties_init(zval *arg, zen
18251829

18261830
ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties) /* {{{ */
18271831
{
1828-
return _object_and_properties_init(arg, class_type, properties);
1832+
return _object_and_properties_init(arg, class_type, properties, false);
18291833
}
18301834
/* }}} */
18311835

18321836
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type) /* {{{ */
18331837
{
1834-
return _object_and_properties_init(arg, class_type, NULL);
1838+
return _object_and_properties_init(arg, class_type, NULL, false);
18351839
}
18361840
/* }}} */
18371841

1842+
ZEND_API zend_result object_init_instantiable_class(zval *arg, zend_class_entry *class_type) /* {{{ */
1843+
{
1844+
return _object_and_properties_init(arg, class_type, NULL, true);
1845+
}
1846+
18381847
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params, HashTable *named_params) /* {{{ */
18391848
{
18401849
if (UNEXPECTED(!zend_check_class_is_instantiable_or_throw(class_type, zend_get_executed_scope()))) {
18411850
ZVAL_UNDEF(arg);
18421851
return FAILURE;
18431852
}
18441853

1845-
zend_result status = _object_and_properties_init(arg, class_type, NULL);
1854+
zend_result status = _object_and_properties_init(arg, class_type, NULL, true);
18461855
if (UNEXPECTED(status == FAILURE)) {
18471856
ZVAL_UNDEF(arg);
18481857
return FAILURE;

Zend/zend_API.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ static zend_always_inline void array_init(zval *arg)
544544

545545
ZEND_API void object_init(zval *arg);
546546
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
547+
ZEND_API zend_result object_init_instantiable_class(zval *arg, zend_class_entry *ce);
547548
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params, HashTable *named_params);
548549
ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
549550
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6008,7 +6008,7 @@ ZEND_VM_HANDLER(68, ZEND_NEW, UNUSED|CLASS_FETCH|CONST|VAR, UNUSED|CACHE_SLOT, N
60086008
HANDLE_EXCEPTION();
60096009
}
60106010

6011-
if (UNEXPECTED(object_init_ex(result, ce) != SUCCESS)) {
6011+
if (UNEXPECTED(object_init_instantiable_class(result, ce) != SUCCESS)) {
60126012
ZVAL_UNDEF(result);
60136013
HANDLE_EXCEPTION();
60146014
}

Zend/zend_vm_execute.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pgsql/pgsql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ PHP_FUNCTION(pg_fetch_object)
21242124
RETURN_THROWS();
21252125
}
21262126

2127-
if (UNEXPECTED(object_init_ex(return_value, ce) == FAILURE)) {
2127+
if (UNEXPECTED(object_init_instantiable_class(return_value, ce) == FAILURE)) {
21282128
RETURN_THROWS();
21292129
}
21302130

0 commit comments

Comments
 (0)