Skip to content

Commit 5e2fad5

Browse files
committed
PHP 8.4 Support: Property hooks (Part 1)
- #8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/property-hooks - Fix the lexer and parser(grammar) - Add `PropertyHookDeclaration` as an `ASTNode` - Fix `PHP5ErrorHandlerImpl` (handle missing tokens) - Fix/Add unit tests for the lexer and parser - Remove `ArrayDimensionSyntaxSuggestionHint` because this no longer works. Example: ```php class PropertyHooksClass { public int $backed = 100 { get { return $this->backed; } set { $this->backed = $value; } } public $doubleArrow { // virtual get => $this->test(); set => $this->test() . $value; } public $attributes { #[Attr1] get {} #[Attr2] set ($value) { $this->attributes = $value; } } public $reference { &get => $this->reference; } public $final { final get => $this->final; } // constructor property promotion public function __construct( public $prop { get { return $this->prop; } set { $this->prop = $value; } } ) {} } class Child extends PropertyHooksClass { public $prop { get => parent::$prop::get(); set { parent::$prop::set($value); } } } interface PropertyHooksInterface { public string $prop1 { get; } final public int $prop2 { set; } public $prop3 { get; set; } public $ref { &get; } } ``` Note: Curly braces array access (`{}` e.g. `$array{1}`, `$array{'key'}`) can use no longer. Because a conflict occurs in the following case: ```php "string"{1}; public string $prop = "string" { get => $this->prop; set {} } ```
1 parent 51fa132 commit 5e2fad5

File tree

211 files changed

+78435
-65686
lines changed

Some content is hidden

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

211 files changed

+78435
-65686
lines changed

php/php.editor/src/org/netbeans/modules/php/editor/lexer/PHP5ColoringLexer.java

Lines changed: 1092 additions & 1067 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php/php.editor/src/org/netbeans/modules/php/editor/lexer/PHPTokenId.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public enum PHPTokenId implements TokenId {
170170
PHP_PARENT(null, "keyword"), //NOI18N
171171
PHP__CLASS__(null, "constant"), //NOI18N
172172
PHP__TRAIT__(null, "constant"), //NOI18N
173+
PHP__PROPERTY__(null, "constant"), //NOI18N PHP 8.4
173174
PHP__METHOD__(null, "constant"), //NOI18N
174175
PHP_TRUE(null, "keyword"), //NOI18N
175176
PHP_FALSE(null, "keyword"), //NOI18N

php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ClassScopeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void addElement(ModelElementImpl element) {
8686
assert element instanceof TypeScope || element instanceof VariableName
8787
|| element instanceof MethodScope || element instanceof FieldElement
8888
|| element instanceof CaseElement // allowed by parser although class can't have cases
89-
|| element instanceof ClassConstantElement : element.getPhpElementKind();
89+
|| element instanceof ClassConstantElement : element.getPhpElementKind() + " " + this.toString();
9090
if (element instanceof TypeScope) {
9191
Scope inScope = getInScope();
9292
if (inScope instanceof ScopeImpl) {

php/php.editor/src/org/netbeans/modules/php/editor/model/impl/FieldElementImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.netbeans.modules.php.editor.model.impl;
2020

21-
import java.util.ArrayList;
2221
import java.util.Collection;
2322
import java.util.Collections;
2423
import java.util.HashSet;
@@ -55,7 +54,7 @@
5554
*/
5655
class FieldElementImpl extends ScopeImpl implements FieldElement {
5756

58-
String defaultType;
57+
private String defaultType;
5958
private String defaultFQType;
6059
private String className;
6160
private final boolean isAnnotation;

php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ public void visit(ConstantDeclaration node) {
822822
@Override
823823
public void visit(SingleFieldDeclaration node) {
824824
scan(node.getValue());
825+
scan(node.getPropertyHooks());
825826
}
826827

827828
@Override

php/php.editor/src/org/netbeans/modules/php/editor/parser/ASTPHP5Parser.java

Lines changed: 3694 additions & 3297 deletions
Large diffs are not rendered by default.

php/php.editor/src/org/netbeans/modules/php/editor/parser/ASTPHP5Scanner.java

Lines changed: 1088 additions & 1061 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php/php.editor/src/org/netbeans/modules/php/editor/parser/ASTPHP5Symbols.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
//----------------------------------------------------
2121
// The following code was generated by CUP v0.11a beta 20060608
22-
// Sun Jan 12 13:42:53 JST 2025
22+
// Wed Jan 29 19:33:57 JST 2025
2323
//----------------------------------------------------
2424

2525
package org.netbeans.modules.php.editor.parser;
@@ -198,6 +198,7 @@ public interface ASTPHP5Symbols {
198198
public static final int T_INSTANCEOF = 23;
199199
public static final int T_DIV_EQUAL = 94;
200200
public static final int T_NUM_STRING = 9;
201+
public static final int T_PROPERTY_C = 175;
201202
public static final int T_HALT_COMPILER = 50;
202203
public static final int T_ENUM = 168;
203204
public static final int T_GOTO = 33;

php/php.editor/src/org/netbeans/modules/php/editor/parser/EncodedActionTable1.java

Lines changed: 2732 additions & 2732 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)