Skip to content

[DRAFT] [WIP] Initial zend_class_alias #18789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert attributes/name/etc.
Just switching to a zend_class_alias object should be easier
  • Loading branch information
DanielEScherzer committed Jun 15, 2025
commit 9dd407cd037a182b7f93d6c3363aeedc916d185a
22 changes: 2 additions & 20 deletions Zend/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,6 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, zend_string *filename)
{
zend_class_entry *ce;
Z_CE_FROM_ZVAL_P(ce, ce_zv);
if (Z_TYPE_P(ce_zv) == IS_ALIAS_PTR) {
return true;
}

if (ce->ce_flags & ZEND_ACC_PRELOADED) {
Bucket *ce_bucket = (Bucket*)((uintptr_t)ce_zv - XtOffsetOf(Bucket, val));
Expand All @@ -787,13 +784,6 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, zend_string *filename)
return false;
}
}
// Ignore deprecated aliases so that they are fetched at runtime
if (Z_TYPE_P(ce_zv) == IS_ALIAS_PTR) {
zend_class_alias *alias = Z_CLASS_ALIAS_P(ce_zv);
if (alias->alias_flags & ZEND_ACC_DEPRECATED) {
return true;
}
}
return ce->type == ZEND_USER_CLASS
&& (!ce->info.user.filename || ce->info.user.filename != filename);
}
Expand Down Expand Up @@ -827,14 +817,7 @@ zend_class_entry *zend_optimizer_get_class_entry(
return Z_PTR_P(ce_or_alias);
}
ZEND_ASSERT(Z_TYPE_P(ce_or_alias) == IS_ALIAS_PTR);
zend_class_alias *alias = Z_CLASS_ALIAS_P(ce_or_alias);
if (alias->alias_flags & ZEND_ACC_DEPRECATED) {
// Pretend that the class cannot be found so that it gets looked
// up at runtime
return NULL;
}
return NULL;
// return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
return Z_CLASS_ALIAS_P(ce_or_alias)->ce;
}

zval *ce_zv = zend_hash_find(CG(class_table), lcname);
Expand All @@ -843,8 +826,7 @@ zend_class_entry *zend_optimizer_get_class_entry(
return Z_PTR_P(ce_zv);
}
ZEND_ASSERT(Z_TYPE_P(ce_zv) == IS_ALIAS_PTR);
return NULL;
// return Z_CLASS_ALIAS_P(ce_zv)->ce;
return Z_CLASS_ALIAS_P(ce_zv)->ce;
}

if (op_array && op_array->scope && zend_string_equals_ci(op_array->scope->name, lcname)) {
Expand Down
24 changes: 11 additions & 13 deletions Zend/tests/attributes/034_target_values.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@ showFlag("TARGET_PROPERTY", Attribute::TARGET_PROPERTY);
showFlag("TARGET_CLASS_CONSTANT", Attribute::TARGET_CLASS_CONSTANT);
showFlag("TARGET_PARAMETER", Attribute::TARGET_PARAMETER);
showFlag("TARGET_CONSTANT", Attribute::TARGET_CONSTANT);
showFlag("TARGET_CLASS_ALIAS", Attribute::TARGET_CLASS_ALIAS);
showFlag("IS_REPEATABLE", Attribute::IS_REPEATABLE);

$all = Attribute::TARGET_CLASS | Attribute::TARGET_FUNCTION
| Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY
| Attribute::TARGET_CLASS_CONSTANT | Attribute::TARGET_PARAMETER
| Attribute::TARGET_CONSTANT | Attribute::TARGET_CLASS_ALIAS;
| Attribute::TARGET_CONSTANT;
var_dump($all, Attribute::TARGET_ALL, $all === Attribute::TARGET_ALL);

?>
--EXPECT--
Attribute::TARGET_CLASS = 1 (255 & 1 === 1)
Attribute::TARGET_FUNCTION = 2 (255 & 2 === 2)
Attribute::TARGET_METHOD = 4 (255 & 4 === 4)
Attribute::TARGET_PROPERTY = 8 (255 & 8 === 8)
Attribute::TARGET_CLASS_CONSTANT = 16 (255 & 16 === 16)
Attribute::TARGET_PARAMETER = 32 (255 & 32 === 32)
Attribute::TARGET_CONSTANT = 64 (255 & 64 === 64)
Attribute::TARGET_CLASS_ALIAS = 128 (255 & 128 === 128)
Attribute::IS_REPEATABLE = 256 (255 & 256 === 0)
int(255)
int(255)
Attribute::TARGET_CLASS = 1 (127 & 1 === 1)
Attribute::TARGET_FUNCTION = 2 (127 & 2 === 2)
Attribute::TARGET_METHOD = 4 (127 & 4 === 4)
Attribute::TARGET_PROPERTY = 8 (127 & 8 === 8)
Attribute::TARGET_CLASS_CONSTANT = 16 (127 & 16 === 16)
Attribute::TARGET_PARAMETER = 32 (127 & 32 === 32)
Attribute::TARGET_CONSTANT = 64 (127 & 64 === 64)
Attribute::IS_REPEATABLE = 128 (127 & 128 === 0)
int(127)
int(127)
bool(true)

This file was deleted.

17 changes: 0 additions & 17 deletions Zend/tests/attributes/class_alias/attributes_array_non-object.phpt

This file was deleted.

21 changes: 0 additions & 21 deletions Zend/tests/attributes/class_alias/attributes_dict.phpt

This file was deleted.

14 changes: 0 additions & 14 deletions Zend/tests/attributes/class_alias/attributes_nonarray.phpt

This file was deleted.

12 changes: 0 additions & 12 deletions Zend/tests/attributes/class_alias/attributes_valid.phpt

This file was deleted.

11 changes: 0 additions & 11 deletions Zend/tests/attributes/class_alias/name_invalid.phpt

This file was deleted.

11 changes: 0 additions & 11 deletions Zend/tests/attributes/class_alias/name_nonstring.phpt

This file was deleted.

15 changes: 0 additions & 15 deletions Zend/tests/attributes/class_alias/name_required.phpt

This file was deleted.

11 changes: 0 additions & 11 deletions Zend/tests/attributes/class_alias/redeclaration_error.phpt

This file was deleted.

25 changes: 0 additions & 25 deletions Zend/tests/attributes/class_alias/repeated_attribute.phpt

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions Zend/tests/attributes/class_alias/target_validation.phpt

This file was deleted.

17 changes: 0 additions & 17 deletions Zend/tests/attributes/class_alias/working_example.phpt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading