Skip to content

Commit 911f9fb

Browse files
committed
Rename to structs
1 parent 0c2ed9e commit 911f9fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+127
-114
lines changed

Zend/tests/data_classes/array_access.phpt renamed to Zend/tests/structs/array_access.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Data classes implementing ArrayAccess
2+
Structs implementing ArrayAccess
33
--FILE--
44
<?php
55

@@ -23,19 +23,19 @@ abstract class VectorBase implements ArrayAccess {
2323
}
2424
}
2525

26-
data class VectorByVal extends VectorBase {
26+
struct VectorByVal extends VectorBase {
2727
public function offsetGet(mixed $offset): mixed {
2828
return $this->elements[$offset];
2929
}
3030
}
3131

32-
data class VectorByRef extends VectorBase {
32+
struct VectorByRef extends VectorBase {
3333
public function &offsetGet(mixed $offset): mixed {
3434
return $this->elements[$offset];
3535
}
3636
}
3737

38-
data class Box {
38+
struct Box {
3939
public function __construct(
4040
public int $value,
4141
) {}

Zend/tests/data_classes/assign_op.phpt renamed to Zend/tests/structs/assign_op.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Assign op on data classes
2+
Assign op on structs
33
--FILE--
44
<?php
55

6-
data class Box {
6+
struct Box {
77
public function __construct(
88
public $value,
99
) {}

Zend/tests/data_classes/assign_ref.phpt renamed to Zend/tests/structs/assign_ref.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Assign ref on data classes
2+
Assign ref on structs
33
--FILE--
44
<?php
55

6-
data class Box {
6+
struct Box {
77
public $value;
88
}
99

Zend/tests/data_classes/assign_to_self.phpt renamed to Zend/tests/structs/assign_to_self.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Send data classes
2+
Send structs
33
--FILE--
44
<?php
55

6-
data class Box {
6+
struct Box {
77
public function __construct(
88
public $value,
99
) {}

Zend/tests/data_classes/basic.phpt renamed to Zend/tests/structs/basic.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Basic data classes
2+
Basic structs
33
--FILE--
44
<?php
55

6-
data class Point {
6+
struct Point {
77
public function __construct(
88
public int $x,
99
public int $y,

Zend/tests/data_classes/interior_immutability.phpt renamed to Zend/tests/structs/interior_immutability.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Basic data classes
2+
Basic structs
33
--FILE--
44
<?php
55

6-
data class Child {
6+
struct Child {
77
public function __construct(
88
public $value,
99
) {}

Zend/tests/data_classes/is_identical.phpt renamed to Zend/tests/structs/is_identical.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
=== on data classes
2+
=== on structs
33
--FILE--
44
<?php
55

6-
data class Box {
6+
struct Box {
77
public function __construct(
88
public $value,
99
) {}
@@ -29,7 +29,7 @@ foreach ($values as $l) {
2929
}
3030

3131
#[\AllowDynamicProperties]
32-
data class Point {}
32+
struct Point {}
3333

3434
$a = new Point();
3535
$a->x = 1;

Zend/tests/data_classes/iter.phpt renamed to Zend/tests/structs/iter.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--TEST--
2-
Iteration of data classes
2+
Iteration of structs
33
--FILE--
44
<?php
55

66
#[AllowDynamicProperties]
7-
data class Box {
7+
struct Box {
88
public $value;
99
}
1010

Zend/tests/data_classes/mutatin_in_ordinary_class.phpt renamed to Zend/tests/structs/mutatin_in_ordinary_class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class Point {
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Mutating modifier may only be added to data class methods in %s on line %d
12+
Fatal error: Mutating modifier may only be added to struct methods in %s on line %d

Zend/tests/data_classes/mutating_call_verification.phpt renamed to Zend/tests/structs/mutating_call_verification.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Mutating method calls on data classes
2+
Mutating method calls on structs
33
--FILE--
44
<?php
55

6-
data class D {
6+
struct D {
77
public function nonMutating() {
88
echo __FUNCTION__, "\n";
99
}

Zend/tests/data_classes/mutating_methods.phpt renamed to Zend/tests/structs/mutating_methods.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Mutating method calls on data classes
2+
Mutating method calls on structs
33
--FILE--
44
<?php
55

6-
data class Point {
6+
struct Point {
77
public function __construct(
88
public int $x,
99
public int $y,
@@ -15,7 +15,7 @@ data class Point {
1515
}
1616
}
1717

18-
data class Shape {
18+
struct Shape {
1919
public function __construct(
2020
public Point $position,
2121
) {}

Zend/tests/data_classes/nested.phpt renamed to Zend/tests/structs/nested.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
--TEST--
2-
Nested data classes
2+
Nested structs
33
--FILE--
44
<?php
55

6-
data class Point {
6+
struct Point {
77
public function __construct(
88
public int $x,
99
public int $y,
1010
) {}
1111
}
1212

13-
data class Shape {
13+
struct Shape {
1414
public function __construct(
1515
public Point $position,
1616
) {}

Zend/tests/data_classes/nested_references.phpt renamed to Zend/tests/structs/nested_references.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Data classes in nested references
2+
Structs in nested references
33
--FILE--
44
<?php
55

6-
data class Point {
6+
struct Point {
77
public function __construct(
88
public int $x,
99
public int $y,
@@ -15,7 +15,7 @@ data class Point {
1515
}
1616
}
1717

18-
data class Shape {
18+
struct Shape {
1919
public function __construct(
2020
public Point &$position,
2121
) {}

Zend/tests/data_classes/pre_post_inc_dec.phpt renamed to Zend/tests/structs/pre_post_inc_dec.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
++/-- on data classes
2+
++/-- on structs
33
--FILE--
44
<?php
55

6-
data class Box {
6+
struct Box {
77
public function __construct(
88
public $value,
99
) {}

Zend/tests/data_classes/references.phpt renamed to Zend/tests/structs/references.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Data classes in references
2+
Structs in references
33
--FILE--
44
<?php
55

6-
data class Point {
6+
struct Point {
77
public function __construct(
88
public int $x,
99
public int $y,

Zend/tests/data_classes/send.phpt renamed to Zend/tests/structs/send.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Send data classes
2+
Send structs
33
--FILE--
44
<?php
55

6-
data class Box {
6+
struct Box {
77
public $value;
88
}
99

Zend/tests/data_classes/separating_fetch_this.phpt renamed to Zend/tests/structs/separating_fetch_this.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
FETCH_THIS in data class method must separate
2+
FETCH_THIS in struct method must separate
33
--FILE--
44
<?php
55

6-
data class Point {
6+
struct Point {
77
public function __construct(
88
public int $x,
99
public int $y,

Zend/tests/weakrefs/weakmap_data_classes.phpt renamed to Zend/tests/weakrefs/weakmap_structs.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
WeakMaps disallow data classes
2+
WeakMaps disallow structs
33
--FILE--
44
<?php
55

6-
data class DC {}
6+
struct DC {}
77

88
function test($c) {
99
$map = new WeakMap();
@@ -31,7 +31,7 @@ test(function ($map, $dc) {
3131

3232
?>
3333
--EXPECT--
34-
Instance of data class DC may not be used as key
35-
Instance of data class DC may not be used as key
36-
Instance of data class DC may not be used as key
37-
Instance of data class DC may not be used as key
34+
Instance of struct DC may not be used as key
35+
Instance of struct DC may not be used as key
36+
Instance of struct DC may not be used as key
37+
Instance of struct DC may not be used as key

Zend/zend_API.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5111,6 +5111,8 @@ ZEND_API ZEND_COLD const char *zend_get_object_type_case(const zend_class_entry
51115111
return upper_case ? "Interface" : "interface";
51125112
} else if (ce->ce_flags & ZEND_ACC_ENUM) {
51135113
return upper_case ? "Enum" : "enum";
5114+
} else if (ce->ce_flags & ZEND_ACC_STRUCT) {
5115+
return upper_case ? "Struct" : "struct";
51145116
} else {
51155117
return upper_case ? "Class" : "class";
51165118
}

Zend/zend_compile.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7776,8 +7776,8 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
77767776
if (is_method) {
77777777
bool has_body = stmt_ast != NULL;
77787778
lcname = zend_begin_method_decl(op_array, decl->name, has_body);
7779-
if ((op_array->fn_flags & ZEND_ACC_MUTATING) && !(op_array->scope->ce_flags & ZEND_ACC_DATA_CLASS)) {
7780-
zend_error_noreturn(E_COMPILE_ERROR, "Mutating modifier may only be added to data class methods");
7779+
if ((op_array->fn_flags & ZEND_ACC_MUTATING) && !(op_array->scope->ce_flags & ZEND_ACC_STRUCT)) {
7780+
zend_error_noreturn(E_COMPILE_ERROR, "Mutating modifier may only be added to struct methods");
77817781
}
77827782
} else {
77837783
lcname = zend_begin_func_decl(result, op_array, decl, toplevel);
@@ -8257,6 +8257,10 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)
82578257

82588258
zend_class_entry *original_ce = CG(active_class_entry);
82598259

8260+
if (decl->flags & ZEND_ACC_STRUCT) {
8261+
// TODO: ABSTRACT, FINAL, READONLY
8262+
}
8263+
82608264
if (EXPECTED((decl->flags & ZEND_ACC_ANON_CLASS) == 0)) {
82618265
zend_string *unqualified_name = decl->name;
82628266

Zend/zend_compile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ typedef struct _zend_oparray_context {
315315
/* Class cannot be serialized or unserialized | | | */
316316
#define ZEND_ACC_NOT_SERIALIZABLE (1 << 29) /* X | | | */
317317
/* | | | */
318-
/* Data classes are value types | | | */
319-
#define ZEND_ACC_DATA_CLASS (1 << 30) /* X | | | */
318+
/* Structs are value types | | | */
319+
#define ZEND_ACC_STRUCT (1 << 30) /* X | | | */
320320
/* | | | */
321321
/* Function Flags (unused: 30) | | | */
322322
/* ============== | | | */
@@ -380,7 +380,7 @@ typedef struct _zend_oparray_context {
380380
/* has #[\Override] attribute | | | */
381381
#define ZEND_ACC_OVERRIDE (1 << 28) /* | X | | */
382382
/* | | | */
383-
/* Mutating function of a data class | | | */
383+
/* Mutating function of a struct | | | */
384384
#define ZEND_ACC_MUTATING (1 << 29) /* | X | | */
385385
/* | | | */
386386
/* op_array uses strict mode types | | | */

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3209,7 +3209,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
32093209
* to make sure no actual modification is possible. */
32103210
ZEND_ASSERT(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET);
32113211
if (Z_TYPE_P(ptr) == IS_OBJECT
3212-
&& EXPECTED(!(Z_OBJCE_P(ptr)->ce_flags & ZEND_ACC_DATA_CLASS))) {
3212+
&& EXPECTED(!(Z_OBJCE_P(ptr)->ce_flags & ZEND_ACC_STRUCT))) {
32133213
ZVAL_COPY(result, ptr);
32143214
} else if (Z_PROP_FLAG_P(ptr) & IS_PROP_REINITABLE) {
32153215
Z_PROP_FLAG_P(ptr) &= ~IS_PROP_REINITABLE;

Zend/zend_language_parser.y

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
162162
%token <ident> T_EMPTY "'empty'"
163163
%token <ident> T_HALT_COMPILER "'__halt_compiler'"
164164
%token <ident> T_CLASS "'class'"
165-
%token <ident> T_DATA_CLASS "'data class'"
165+
%token <ident> T_STRUCT "'struct'"
166166
%token <ident> T_TRAIT "'trait'"
167167
%token <ident> T_INTERFACE "'interface'"
168168
%token <ident> T_ENUM "'enum'"
@@ -285,6 +285,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
285285
%type <num> returns_ref function fn is_reference is_variadic property_modifiers
286286
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
287287
%type <num> class_modifiers class_modifier anonymous_class_modifiers anonymous_class_modifiers_optional use_type backup_fn_flags
288+
%type <num> class_like
288289

289290
%type <ptr> backup_lex_pos
290291
%type <str> backup_doc_comment
@@ -303,7 +304,7 @@ reserved_non_modifiers:
303304
| T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH | T_FINALLY
304305
| T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
305306
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT | T_BREAK
306-
| T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
307+
| T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS | T_STRUCT
307308
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_FN | T_MATCH | T_ENUM
308309
;
309310

@@ -317,6 +318,11 @@ ampersand:
317318
| T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG
318319
;
319320

321+
class_like:
322+
T_CLASS { $$ = 0; }
323+
| T_STRUCT { $$ = ZEND_ACC_STRUCT; }
324+
;
325+
320326
identifier:
321327
T_STRING { $$ = $1; }
322328
| semi_reserved {
@@ -589,15 +595,12 @@ is_variadic:
589595
;
590596

591597
class_declaration_statement:
592-
class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
593-
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
594-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL, NULL); }
595-
| T_CLASS { $<num>$ = CG(zend_lineno); }
598+
class_modifiers class_like { $<num>$ = CG(zend_lineno); }
596599
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
597-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
598-
| T_DATA_CLASS { $<num>$ = CG(zend_lineno); }
600+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1 | $2, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL, NULL); }
601+
| class_like { $<num>$ = CG(zend_lineno); }
599602
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
600-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_DATA_CLASS, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
603+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
601604
;
602605

603606
class_modifiers:

0 commit comments

Comments
 (0)