Skip to content

Commit e8614ca

Browse files
Try
1 parent 3c66371 commit e8614ca

9 files changed

Lines changed: 40 additions & 14 deletions

File tree

Zend/Optimizer/zend_optimizer.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, const zend_string *filename
779779
{
780780
const zend_class_entry *ce;
781781
Z_CE_FROM_ZVAL_P(ce, ce_zv);
782+
if (Z_TYPE_P(ce_zv) == IS_ALIAS_PTR) {
783+
return true;
784+
}
782785

783786
if (ce->ce_flags & ZEND_ACC_PRELOADED) {
784787
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
@@ -839,7 +842,8 @@ zend_class_entry *zend_optimizer_get_class_entry(
839842
// up at runtime
840843
return NULL;
841844
}
842-
return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
845+
return NULL;
846+
// return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
843847
}
844848

845849
zval *ce_zv = zend_hash_find(CG(class_table), lcname);
@@ -848,7 +852,8 @@ zend_class_entry *zend_optimizer_get_class_entry(
848852
return Z_PTR_P(ce_zv);
849853
}
850854
ZEND_ASSERT(Z_TYPE_P(ce_zv) == IS_ALIAS_PTR);
851-
return Z_CLASS_ALIAS_P(ce_zv)->ce;
855+
return NULL;
856+
// return Z_CLASS_ALIAS_P(ce_zv)->ce;
852857
}
853858

854859
if (op_array && op_array->scope && zend_string_equals_ci(op_array->scope->name, lcname)) {
@@ -891,7 +896,7 @@ const zend_class_constant *zend_fetch_class_const_info(
891896
} else {
892897
zval *ce_zv = zend_hash_find(EG(class_table), Z_STR_P(op1 + 1));
893898
if (ce_zv && !zend_optimizer_ignore_class(ce_zv, op_array->filename)) {
894-
ce = Z_PTR_P(ce_zv);
899+
Z_CE_FROM_ZVAL_P(ce, ce_zv);
895900
}
896901
}
897902
}

Zend/tests/attributes/class_alias/attributes_dict.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Alias attributes must not be associative
66
#[ClassAlias('Other', ['test' => new Deprecated()])]
77
class Demo {}
88

9+
class_alias( 'Demo', 'Other2' );
10+
911
$attr = new ReflectionClass( Demo::class )->getAttributes()[0];
1012
$attr->newInstance();
1113

Zend/zend_API.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,6 +3633,7 @@ ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_
36333633
}
36343634

36353635
zend_string_release(original_name);
3636+
free(alias);
36363637
return FAILURE;
36373638
}
36383639
/* }}} */

Zend/zend_attributes.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ static void validate_class_alias(
337337
goto restore_execution_data;
338338
}
339339

340+
// if (CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) {
341+
// // Opcache, don't register the alias
342+
// goto restore_execution_data;
343+
// }
344+
340345
zend_result result = zend_register_class_alias_ex(
341346
ZSTR_VAL(alias),
342347
ZSTR_LEN(alias),
@@ -660,10 +665,6 @@ ZEND_API zend_result zend_get_attribute_value(zval *ret, const zend_attribute *a
660665
ZVAL_COPY_OR_DUP(ret, &attr->args[i].value);
661666

662667
if (Z_TYPE_P(ret) == IS_CONSTANT_AST) {
663-
// Delayed validation for attributes in class aliases
664-
if (CG(in_compilation) && i == 1 && zend_string_equals(attr->name, zend_ce_class_alias->name)) {
665-
return SUCCESS;
666-
}
667668
if (SUCCESS != zval_update_constant_ex(ret, scope)) {
668669
zval_ptr_dtor(ret);
669670
return FAILURE;

Zend/zend_execute_API.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
327327
}
328328
} ZEND_HASH_FOREACH_END();
329329
ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) {
330-
if (Z_TYPE_P(zv) == IS_ALIAS_PTR) {
331-
continue;
332-
}
330+
// CHECK
331+
// if (Z_TYPE_P(zv) == IS_ALIAS_PTR) {
332+
// continue;
333+
// }
333334
zend_class_entry *ce;
334335
Z_CE_FROM_ZVAL_P(ce, zv);
335336

Zend/zend_opcode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ ZEND_API void destroy_zend_class(zval *zv)
311311
if (UNEXPECTED(Z_TYPE_INFO_P(zv) == IS_ALIAS_PTR)) {
312312
zend_class_alias *class_alias = Z_CLASS_ALIAS_P(zv);
313313

314+
if (class_alias->alias_flags & ZEND_ACC_IMMUTABLE) {
315+
return;
316+
}
317+
314318
if (class_alias->attributes) {
315319
zend_hash_release(class_alias->attributes);
316320
// class_alias->attributes = NULL;

ext/opcache/ZendAccelerator.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,16 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
686686

687687
/* class table hash keys, class names, properties, methods, constants, etc */
688688
ZEND_HASH_MAP_FOREACH_BUCKET(CG(class_table), p) {
689-
zend_class_entry *ce;
689+
zend_class_entry *ce = NULL;
690690

691-
Z_CE_FROM_ZVAL(ce, p->val);
691+
if (EXPECTED(Z_TYPE(p->val) == IS_PTR)) {
692+
ce = Z_PTR(p->val);
693+
} else {
694+
ZEND_ASSERT(Z_TYPE(p->val) == IS_ALIAS_PTR);
695+
zend_class_alias *alias = Z_PTR(p->val);
696+
alias->name = new_interned_string(alias->name);
697+
ce = alias->ce;
698+
}
692699

693700
if (p->key) {
694701
p->key = new_interned_string(p->key);
@@ -4141,8 +4148,6 @@ static void preload_link(void)
41414148
zend_hash_index_del(
41424149
CG(delayed_variance_obligations), (uintptr_t) Z_CE_P(zv));
41434150
}
4144-
zend_hash_index_del(
4145-
CG(delayed_variance_obligations), (uintptr_t) Z_CE_P(zv));
41464151
}
41474152

41484153
/* Restore the original class. */

ext/opcache/zend_file_cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
16741674
zend_persistent_script *script,
16751675
void *buf)
16761676
{
1677+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_PTR);
16771678
zend_class_entry *ce;
16781679

16791680
UNSERIALIZE_PTR(Z_PTR_P(zv));

ext/opcache/zend_persist.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,12 @@ zend_class_alias *zend_persist_class_alias_entry(zend_class_alias *orig_alias)
925925
alias->attributes = zend_persist_attributes(alias->attributes);
926926
}
927927

928+
if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
929+
alias->alias_flags |= ZEND_ACC_IMMUTABLE;
930+
} else {
931+
alias->alias_flags |= ZEND_ACC_FILE_CACHED;
932+
}
933+
928934
return alias;
929935
}
930936

0 commit comments

Comments
 (0)