Skip to content

Rfc: inner class2 #3

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

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a6e974c
add new token
withinboredom Mar 8, 2025
ad91fee
create the new grammar
withinboredom Mar 8, 2025
095af03
add new ast pieces
withinboredom Mar 8, 2025
86b0c22
handle modifiers
withinboredom Mar 8, 2025
3ac09a6
handle compiling class declarations
withinboredom Mar 8, 2025
2042a8e
add initial implementation;
withinboredom Mar 8, 2025
6f196e2
get return types working
withinboredom Mar 9, 2025
2e7d28a
make ::class work
withinboredom Mar 9, 2025
92b0dc6
fix failing test
withinboredom Mar 9, 2025
f3f2c16
add another class
withinboredom Mar 9, 2025
551e139
add more tests to validate scope resolution keywords
withinboredom Mar 9, 2025
13d8b39
update reflection
withinboredom Mar 9, 2025
3f5e6af
enable visibility
withinboredom Mar 9, 2025
10551f5
add tests for autoloading
withinboredom Mar 9, 2025
78ef744
properly persist classes in opcache
withinboredom Mar 9, 2025
8855f01
handle return type visibility enforcement
withinboredom Mar 9, 2025
d1694f9
fix static member access
withinboredom Mar 11, 2025
5386389
move tests
withinboredom Mar 13, 2025
05ab0e0
add more tests and fix access modifiers
withinboredom Mar 13, 2025
b510b5f
add support for lexical scope
withinboredom Mar 13, 2025
eefea57
handle type visibility
withinboredom Mar 14, 2025
356c0f1
fix opcache
withinboredom Mar 14, 2025
d4bf058
fix test
withinboredom Mar 14, 2025
c669844
refine some error messages
withinboredom Mar 14, 2025
49a9427
add type check to return type
withinboredom Mar 14, 2025
4313dfb
fix tests
withinboredom Mar 14, 2025
0414f58
temporarily fix this test -- might want to undo this
withinboredom Mar 14, 2025
42eee19
clean up a bit and check readonly
withinboredom Mar 14, 2025
9f654a1
handle visibility of methods
withinboredom Mar 14, 2025
910fc8c
just do not cache -- more trouble than it is worth right now
withinboredom Mar 14, 2025
490ea8b
properly handle lexical scope
withinboredom Mar 14, 2025
15ea80c
handle long names
withinboredom Mar 14, 2025
4ee4332
handle more visibility
withinboredom Mar 14, 2025
566884c
handle constructor visibility
withinboredom Mar 15, 2025
53701d1
prevent static access
withinboredom Mar 15, 2025
b33d9c1
start making \\ the separator instead of :>
withinboredom Mar 23, 2025
8d471c7
update tests
withinboredom Mar 23, 2025
17fa07c
finish up edge cases and tests
withinboredom Mar 23, 2025
71a7f6d
fix traits
withinboredom Mar 23, 2025
2767025
make autoloading more effecient
withinboredom Mar 23, 2025
7119f6c
fix attributes
withinboredom Mar 23, 2025
a05c5db
properly handle searching up the scope
withinboredom Mar 23, 2025
3f31e15
refactor all-the-things
withinboredom Mar 24, 2025
141995f
refactor all-the-things
withinboredom Mar 24, 2025
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
2 changes: 1 addition & 1 deletion Zend/tests/errmsg/errmsg_027.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class test {
echo "Done\n";
?>
--EXPECTF--
Fatal error: Class declarations may not be nested in %s on line %d
Fatal error: Class declarations may not be declared inside functions in %s on line %d
4 changes: 4 additions & 0 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ struct _zend_class_entry {
HashTable properties_info;
HashTable constants_table;

zend_class_entry *required_scope;
zend_class_entry *lexical_scope;
char required_scope_absolute;

ZEND_MAP_PTR_DEF(zend_class_mutable_data*, mutable_data);
zend_inheritance_cache_entry *inheritance_cache;

Expand Down
15 changes: 15 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,21 @@ static zend_always_inline zend_result _object_and_properties_init(zval *arg, zen
return FAILURE;
}

if (class_type->required_scope) {
const zend_class_entry *scope = zend_get_executed_scope();
if (scope == NULL) {
zend_error(E_ERROR, "Cannot instantiate \"%s\" from the global scope", ZSTR_VAL(class_type->name));
}

if (class_type->required_scope_absolute) {
if (scope != class_type->required_scope && scope->lexical_scope != class_type->required_scope) {
zend_error(E_ERROR, "Cannot instantiate private \"%s\" from \"%s\"", ZSTR_VAL(class_type->name), ZSTR_VAL(scope->name));
}
} else if (!instanceof_function(scope, class_type->required_scope) && !instanceof_function(scope->lexical_scope, class_type->required_scope)) {
zend_error(E_ERROR, "Cannot instantiate protected \"%s\" from \"%s\"", ZSTR_VAL(class_type->name), ZSTR_VAL(scope->name));
}
}

if (UNEXPECTED(!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
if (UNEXPECTED(zend_update_class_constants(class_type) != SUCCESS)) {
ZVAL_NULL(arg);
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ enum _zend_ast_kind {
ZEND_AST_YIELD,
ZEND_AST_COALESCE,
ZEND_AST_ASSIGN_COALESCE,
ZEND_AST_INNER_CLASS,

ZEND_AST_STATIC,
ZEND_AST_WHILE,
Expand Down
Loading
Loading