Skip to content

Commit fee66bf

Browse files
Try
1 parent dcef3d4 commit fee66bf

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
@@ -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
const Bucket *ce_bucket = (const Bucket*)((uintptr_t)ce_zv - XtOffsetOf(Bucket, val));
@@ -833,7 +836,8 @@ zend_class_entry *zend_optimizer_get_class_entry(
833836
// up at runtime
834837
return NULL;
835838
}
836-
return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
839+
return NULL;
840+
// return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
837841
}
838842

839843
zval *ce_zv = zend_hash_find(CG(class_table), lcname);
@@ -842,7 +846,8 @@ zend_class_entry *zend_optimizer_get_class_entry(
842846
return Z_PTR_P(ce_zv);
843847
}
844848
ZEND_ASSERT(Z_TYPE_P(ce_zv) == IS_ALIAS_PTR);
845-
return Z_CLASS_ALIAS_P(ce_zv)->ce;
849+
return NULL;
850+
// return Z_CLASS_ALIAS_P(ce_zv)->ce;
846851
}
847852

848853
if (op_array && op_array->scope && zend_string_equals_ci(op_array->scope->name, lcname)) {
@@ -885,7 +890,7 @@ const zend_class_constant *zend_fetch_class_const_info(
885890
} else {
886891
zval *ce_zv = zend_hash_find(EG(class_table), Z_STR_P(op1 + 1));
887892
if (ce_zv && !zend_optimizer_ignore_class(ce_zv, op_array->filename)) {
888-
ce = Z_PTR_P(ce_zv);
893+
Z_CE_FROM_ZVAL_P(ce, ce_zv);
889894
}
890895
}
891896
}

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
@@ -3613,6 +3613,7 @@ ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_
36133613
}
36143614

36153615
zend_string_release(original_name);
3616+
free(alias);
36163617
return FAILURE;
36173618
}
36183619
/* }}} */

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
@@ -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
@@ -300,6 +300,10 @@ ZEND_API void destroy_zend_class(zval *zv)
300300
if (UNEXPECTED(Z_TYPE_INFO_P(zv) == IS_ALIAS_PTR)) {
301301
zend_class_alias *class_alias = Z_CLASS_ALIAS_P(zv);
302302

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

ext/opcache/ZendAccelerator.c

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

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

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

689696
if (p->key) {
690697
p->key = new_interned_string(p->key);
@@ -4119,8 +4126,6 @@ static void preload_link(void)
41194126
zend_hash_index_del(
41204127
CG(delayed_variance_obligations), (uintptr_t) Z_CE_P(zv));
41214128
}
4122-
zend_hash_index_del(
4123-
CG(delayed_variance_obligations), (uintptr_t) Z_CE_P(zv));
41244129
}
41254130

41264131
/* Restore the original class. */

ext/opcache/zend_file_cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
16641664
zend_persistent_script *script,
16651665
void *buf)
16661666
{
1667+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_PTR);
16671668
zend_class_entry *ce;
16681669

16691670
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
@@ -924,6 +924,12 @@ zend_class_alias *zend_persist_class_alias_entry(zend_class_alias *orig_alias)
924924
alias->attributes = zend_persist_attributes(alias->attributes);
925925
}
926926

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

0 commit comments

Comments
 (0)