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
Names in deprecation warnings
  • Loading branch information
DanielEScherzer committed Jun 9, 2025
commit cc2d2c331964205aa16e4fcf0487ddda680b158b
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ var_dump(MyAlias::TEST);

?>
--EXPECTF--
Deprecated: Alias is deprecated in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated in %s on line %d
int(1)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ MyAlias::$v = true;

?>
--EXPECTF--
Deprecated: Alias is deprecated in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ MyAlias::doNothing();

?>
--EXPECTF--
Deprecated: Alias is deprecated in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated in %s on line %d
Clazz::doNothing
8 changes: 4 additions & 4 deletions Zend/tests/attributes/deprecated/class_alias/messages.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ MyAlias::doNothing();

?>
--EXPECTF--
Deprecated: Alias is deprecated since 8.4, don't use the alias in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated since 8.4, don't use the alias in %s on line %d
int(1)

Deprecated: Alias is deprecated since 8.4, don't use the alias in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated since 8.4, don't use the alias in %s on line %d

Deprecated: Alias is deprecated since 8.4, don't use the alias in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated since 8.4, don't use the alias in %s on line %d

Deprecated: Alias is deprecated since 8.4, don't use the alias in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated since 8.4, don't use the alias in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ $o = new MyAlias();

?>
--EXPECTF--
Deprecated: Alias is deprecated in %s on line %d
Deprecated: Alias MyAlias for class Clazz is deprecated in %s on line %d
Clazz::__construct
3 changes: 3 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,9 @@ ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_
*/
zend_class_alias *alias = zend_class_alias_init(ce);

zend_string *original_name = zend_string_init(name, name_len, persistent);
alias->name = original_name;

ZVAL_ALIAS_PTR(&zv, alias);

ret = zend_hash_add(CG(class_table), lcname, &zv);
Expand Down
5 changes: 4 additions & 1 deletion Zend/zend_class_alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ zend_class_alias * zend_class_alias_init(zend_class_entry *ce) {
GC_SET_REFCOUNT(alias, 1);

alias->ce = ce;
alias->name = NULL;
alias->attributes = NULL;
alias->alias_flags = 0;

Expand All @@ -42,7 +43,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_class_alias(const zend_cla
return;
}

zend_error_unchecked(E_USER_DEPRECATED, "Alias is deprecated%S",
zend_error_unchecked(E_USER_DEPRECATED, "Alias %s for class %s is deprecated%S",
ZSTR_VAL(alias->name),
ZSTR_VAL(alias->ce->name),
message_suffix
);

Expand Down
1 change: 1 addition & 0 deletions Zend/zend_class_alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
struct _zend_class_alias {
zend_refcounted_h gc;
zend_class_entry *ce;
zend_string *name;
HashTable *attributes;
uint32_t alias_flags;
};
Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ ZEND_API void destroy_zend_class(zval *zv)
zend_hash_release(class_alias->attributes);
class_alias->attributes = NULL;
}
if (class_alias->name) {
zend_string_release(class_alias->name);
class_alias->name = NULL;
}
return;
}

Expand Down