Skip to content

Commit d38277b

Browse files
Add deprecation
Not yet wired to emit anything yet though
1 parent 2adfea9 commit d38277b

8 files changed

+63
-2
lines changed

Zend/zend_attributes.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,16 @@ static void validate_class_alias(
366366
} else {
367367
zend_ast *attributes_ast = Z_ASTVAL_P(nested_attribs);
368368
compile_alias_attributes(&( alias_obj->attributes), attributes_ast);
369+
370+
zend_attribute *deprecated_attribute = zend_get_attribute_str(
371+
alias_obj->attributes,
372+
"deprecated",
373+
strlen("deprecated")
374+
);
375+
376+
if (deprecated_attribute) {
377+
alias_obj->alias_flags |= ZEND_ACC_DEPRECATED;
378+
}
369379
}
370380
}
371381

Zend/zend_class_alias.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ zend_class_alias * zend_class_alias_init(zend_class_entry *ce) {
2525

2626
alias->ce = ce;
2727
alias->attributes = NULL;
28+
alias->alias_flags = 0;
2829

2930
return alias;
3031
}

Zend/zend_class_alias.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct _zend_class_alias {
2525
zend_refcounted_h gc;
2626
zend_class_entry *ce;
2727
HashTable *attributes;
28+
uint32_t alias_flags;
2829
};
2930

3031
typedef struct _zend_class_alias zend_class_alias;

ext/reflection/php_reflection.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7922,13 +7922,25 @@ ZEND_METHOD(ReflectionClassAlias, __toString)
79227922

79237923
smart_str_append_printf(
79247924
&str,
7925-
"%s - alias for %s",
7925+
"%s - %salias for %s",
79267926
Z_STRVAL_P(reflection_prop_name(ZEND_THIS)),
7927+
(alias->alias_flags & ZEND_ACC_DEPRECATED) ? "deprecated " : "",
79277928
ZSTR_VAL(alias->ce->name)
79287929
);
79297930
RETURN_STR(smart_str_extract(&str));
79307931
}
79317932

7933+
ZEND_METHOD(ReflectionClassAlias, isDeprecated)
7934+
{
7935+
reflection_object *intern;
7936+
zend_class_alias *alias;
7937+
7938+
ZEND_PARSE_PARAMETERS_NONE();
7939+
7940+
GET_REFLECTION_OBJECT_PTR(alias);
7941+
RETURN_BOOL(alias->alias_flags & ZEND_ACC_DEPRECATED);
7942+
}
7943+
79327944
PHP_MINIT_FUNCTION(reflection) /* {{{ */
79337945
{
79347946
memcpy(&reflection_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,5 +939,7 @@ public function __construct(string $name) {}
939939

940940
public function __toString(): string {}
941941

942+
public function isDeprecated(): bool {}
943+
942944
public function getAttributes(?string $name = null, int $flags = 0): array {}
943945
}

ext/reflection/php_reflection_arginfo.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
ReflectionClassAlias::isDeprecated()
3+
--FILE--
4+
<?php
5+
6+
#[ClassAlias('OldAlias', [new Deprecated()])]
7+
#[ClassAlias('NewAlias')]
8+
class Demo {}
9+
10+
$r = new ReflectionClassAlias( 'OldAlias' );
11+
var_dump( $r->isDeprecated() );
12+
13+
$r = new ReflectionClassAlias( 'NewAlias' );
14+
var_dump( $r->isDeprecated() );
15+
?>
16+
--EXPECT--
17+
bool(true)
18+
bool(false)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
ReflectionClassAlias::__toString() for a deprecated alias
3+
--FILE--
4+
<?php
5+
6+
#[ClassAlias('Other', [new Deprecated()])]
7+
class Demo {}
8+
9+
$r = new ReflectionClassAlias( 'Other' );
10+
echo $r;
11+
?>
12+
--EXPECT--
13+
Other - deprecated alias for Demo

0 commit comments

Comments
 (0)