Skip to content

Commit 31ecd01

Browse files
Try
1 parent 966ceab commit 31ecd01

File tree

9 files changed

+40
-14
lines changed

9 files changed

+40
-14
lines changed

Zend/Optimizer/zend_optimizer.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, zend_string *filename)
776776
{
777777
zend_class_entry *ce;
778778
Z_CE_FROM_ZVAL_P(ce, ce_zv);
779+
if (Z_TYPE_P(ce_zv) == IS_ALIAS_PTR) {
780+
return true;
781+
}
779782

780783
if (ce->ce_flags & ZEND_ACC_PRELOADED) {
781784
Bucket *ce_bucket = (Bucket*)((uintptr_t)ce_zv - XtOffsetOf(Bucket, val));
@@ -830,7 +833,8 @@ zend_class_entry *zend_optimizer_get_class_entry(
830833
// up at runtime
831834
return NULL;
832835
}
833-
return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
836+
return NULL;
837+
// return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
834838
}
835839

836840
zval *ce_zv = zend_hash_find(CG(class_table), lcname);
@@ -839,7 +843,8 @@ zend_class_entry *zend_optimizer_get_class_entry(
839843
return Z_PTR_P(ce_zv);
840844
}
841845
ZEND_ASSERT(Z_TYPE_P(ce_zv) == IS_ALIAS_PTR);
842-
return Z_CLASS_ALIAS_P(ce_zv)->ce;
846+
return NULL;
847+
// return Z_CLASS_ALIAS_P(ce_zv)->ce;
843848
}
844849

845850
if (op_array && op_array->scope && zend_string_equals_ci(op_array->scope->name, lcname)) {
@@ -882,7 +887,7 @@ const zend_class_constant *zend_fetch_class_const_info(
882887
} else {
883888
zval *ce_zv = zend_hash_find(EG(class_table), Z_STR_P(op1 + 1));
884889
if (ce_zv && !zend_optimizer_ignore_class(ce_zv, op_array->filename)) {
885-
ce = Z_PTR_P(ce_zv);
890+
Z_CE_FROM_ZVAL_P(ce, ce_zv);
886891
}
887892
}
888893
}

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
@@ -3619,6 +3619,7 @@ ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_
36193619
}
36203620

36213621
zend_string_release(original_name);
3622+
free(alias);
36223623
return FAILURE;
36233624
}
36243625
/* }}} */

Zend/zend_attributes.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ static void validate_class_alias(
303303
goto restore_execution_data;
304304
}
305305

306+
// if (CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) {
307+
// // Opcache, don't register the alias
308+
// goto restore_execution_data;
309+
// }
310+
306311
zend_result result = zend_register_class_alias_ex(
307312
ZSTR_VAL(alias),
308313
ZSTR_LEN(alias),
@@ -612,10 +617,6 @@ ZEND_API zend_result zend_get_attribute_value(zval *ret, zend_attribute *attr, u
612617
ZVAL_COPY_OR_DUP(ret, &attr->args[i].value);
613618

614619
if (Z_TYPE_P(ret) == IS_CONSTANT_AST) {
615-
// Delayed validation for attributes in class aliases
616-
if (CG(in_compilation) && i == 1 && zend_string_equals(attr->name, zend_ce_class_alias->name)) {
617-
return SUCCESS;
618-
}
619620
if (SUCCESS != zval_update_constant_ex(ret, scope)) {
620621
zval_ptr_dtor(ret);
621622
return FAILURE;

Zend/zend_execute_API.c

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

Zend/zend_opcode.c

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

302+
if (class_alias->alias_flags & ZEND_ACC_IMMUTABLE) {
303+
return;
304+
}
305+
302306
if (class_alias->attributes) {
303307
zend_hash_release(class_alias->attributes);
304308
// class_alias->attributes = NULL;

ext/opcache/ZendAccelerator.c

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

682682
/* class table hash keys, class names, properties, methods, constants, etc */
683683
ZEND_HASH_MAP_FOREACH_BUCKET(CG(class_table), p) {
684-
zend_class_entry *ce;
684+
zend_class_entry *ce = NULL;
685685

686-
Z_CE_FROM_ZVAL(ce, p->val);
686+
if (EXPECTED(Z_TYPE(p->val) == IS_PTR)) {
687+
ce = Z_PTR(p->val);
688+
} else {
689+
ZEND_ASSERT(Z_TYPE(p->val) == IS_ALIAS_PTR);
690+
zend_class_alias *alias = Z_PTR(p->val);
691+
alias->name = new_interned_string(alias->name);
692+
ce = alias->ce;
693+
}
687694

688695
if (p->key) {
689696
p->key = new_interned_string(p->key);
@@ -4104,8 +4111,6 @@ static void preload_link(void)
41044111
zend_hash_index_del(
41054112
CG(delayed_variance_obligations), (uintptr_t) Z_CE_P(zv));
41064113
}
4107-
zend_hash_index_del(
4108-
CG(delayed_variance_obligations), (uintptr_t) Z_CE_P(zv));
41094114
}
41104115

41114116
/* Restore the original class. */

ext/opcache/zend_file_cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
16461646
zend_persistent_script *script,
16471647
void *buf)
16481648
{
1649+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_PTR);
16491650
zend_class_entry *ce;
16501651

16511652
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
@@ -921,6 +921,12 @@ zend_class_alias *zend_persist_class_alias_entry(zend_class_alias *orig_alias)
921921
alias->attributes = zend_persist_attributes(alias->attributes);
922922
}
923923

924+
if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
925+
alias->alias_flags |= ZEND_ACC_IMMUTABLE;
926+
} else {
927+
alias->alias_flags |= ZEND_ACC_FILE_CACHED;
928+
}
929+
924930
return alias;
925931
}
926932

0 commit comments

Comments
 (0)