Skip to content

Commit d9330be

Browse files
committed
Improved and documented parameter offsets.
1 parent b905510 commit d9330be

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Zend/zend_attributes.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ZEND_API void zend_attribute_free(zend_attribute *attr)
3838
efree(attr);
3939
}
4040

41-
ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset)
41+
static zend_attribute *get_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset)
4242
{
4343
if (attributes) {
4444
zend_attribute *attr;
@@ -53,7 +53,7 @@ ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *
5353
return NULL;
5454
}
5555

56-
ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset)
56+
static zend_attribute *get_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset)
5757
{
5858
if (attributes) {
5959
zend_attribute *attr;
@@ -70,6 +70,26 @@ ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const cha
7070
return NULL;
7171
}
7272

73+
ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname)
74+
{
75+
return get_attribute(attributes, lcname, 0);
76+
}
77+
78+
ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len)
79+
{
80+
return get_attribute_str(attributes, str, len, 0);
81+
}
82+
83+
ZEND_API zend_attribute *zend_get_parameter_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset)
84+
{
85+
return get_attribute(attributes, lcname, offset + 1);
86+
}
87+
88+
ZEND_API zend_attribute *zend_get_parameter_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset)
89+
{
90+
return get_attribute_str(attributes, str, len, offset + 1);
91+
}
92+
7393
ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator)
7494
{
7595
zend_string *lcname = zend_string_tolower_ex(ce->name, 1);

Zend/zend_attributes.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern ZEND_API zend_class_entry *zend_ce_php_compiler_attribute;
1919
typedef struct _zend_attribute {
2020
zend_string *name;
2121
zend_string *lcname;
22+
/* Parameter offsets start at 1, everything else uses 0. */
2223
uint32_t offset;
2324
uint32_t argc;
2425
zval argv[1];
@@ -28,8 +29,11 @@ typedef void (*zend_attributes_internal_validator)(zend_attribute *attr, int tar
2829

2930
ZEND_API void zend_attribute_free(zend_attribute *attr);
3031

31-
ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset);
32-
ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset);
32+
ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname);
33+
ZEND_API zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len);
34+
35+
ZEND_API zend_attribute *zend_get_parameter_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset);
36+
ZEND_API zend_attribute *zend_get_parameter_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset);
3337

3438
ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator);
3539
ZEND_API zend_attributes_internal_validator zend_attribute_get_validator(zend_string *lcname);

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6582,7 +6582,7 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
65826582
RETURN_THROWS();
65836583
}
65846584

6585-
if (ce->type == ZEND_USER_CLASS && !zend_get_attribute_str(ce->info.user.attributes, ZEND_STRL("phpattribute"), 0)) {
6585+
if (ce->type == ZEND_USER_CLASS && !zend_get_attribute_str(ce->info.user.attributes, ZEND_STRL("phpattribute"))) {
65866586
zend_throw_error(NULL, "Attempting to use class '%s' as attribute that does not have <<PhpAttribute>>.", ZSTR_VAL(attr->data->name));
65876587
RETURN_THROWS();
65886588
} else if (ce->type == ZEND_INTERNAL_CLASS && !zend_attribute_get_validator(attr->data->lcname)) {

0 commit comments

Comments
 (0)