Skip to content
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

PHP 8.3 Lazy static initialization for non constants #8073

Closed
Wukkopi opened this issue Dec 18, 2024 · 2 comments · Fixed by #8085
Closed

PHP 8.3 Lazy static initialization for non constants #8073

Wukkopi opened this issue Dec 18, 2024 · 2 comments · Fixed by #8085
Assignees
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor)
Milestone

Comments

@Wukkopi
Copy link

Wukkopi commented Dec 18, 2024

Apache NetBeans version

Apache NetBeans 24

What happened

I'm getting syntax error on valid syntax when language level is on 8.3.

Since PHP 8.3 lazy static initialization happens during runtime instead of compile time, allowing non-constants to be assigned (functions, and even class variables).

Language / Project Type / NetBeans Component

No response

How to reproduce

class MyClass
{
    private int $variable = 1;
    function run() : void
    {
        static $functionResult = rand(); // shows "unexpected '(' after rand" error
        static $classVariable = $this->variable; // shows "unexpected '$this' after =" error
    }
}

Did this work correctly in an earlier version?

No / Don't know

Operating System

Debian 12

JDK

OpenJDK 64-Bit Server VM (build 17.0.13+11-Debian-2deb12u1, mixed mode, sharing)

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

@Wukkopi Wukkopi added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Dec 18, 2024
@troizet troizet added the PHP [ci] enable extra PHP tests (php/php.editor) label Dec 18, 2024
@junichi11 junichi11 self-assigned this Dec 18, 2024
@junichi11 junichi11 removed the needs:triage Requires attention from one of the committers label Dec 18, 2024
@junichi11
Copy link
Member

@junichi11 junichi11 added this to the NB25 milestone Dec 19, 2024
junichi11 added a commit to junichi11/netbeans that referenced this issue Dec 23, 2024
- apache#6701
- apache#8073
- https://wiki.php.net/rfc/arbitrary_static_variable_initializers
- Fix the grammar file (parser)
- Add unit tests for the parser

Example:
```php
class Example {
    private int $field = 1;

    public function method(): int {
        return 1;
    }

    public function run(int $param1) : void {
        static $example1 = rand();
        static $example2 = $param1;
        static $example3 = $this->field;
        static $example4 = $this->method();
        static $example5 = new class() {};
        static $example6 = new stdClass(...[0]);
        static $example6 = new stdClass($param1);
        static $example7 = new (Test);
        static $example8 = new static;
        static $example9 = $param1 <= 100 ? run($param1 + 1) : "Test $param1";
        static $example10 = rand(), $example11 = rand();
    }
}

$variable = 1;
static $example1 = rand();
static $example2 = $variable;
```
junichi11 added a commit to junichi11/netbeans that referenced this issue Dec 23, 2024
- apache#6701
- apache#8073
- https://wiki.php.net/rfc/arbitrary_static_variable_initializers
- Fix the formatter
- Add unit tests
  - Formatter
  - Code Completion
  - GotoDeclaration and MarkOccurrences
junichi11 added a commit to junichi11/netbeans that referenced this issue Dec 23, 2024
- apache#6701
- apache#8073
- https://wiki.php.net/rfc/arbitrary_static_variable_initializers
- Fix the `PHP83UnhandledError`
- Fix the bracket barance for the `ASTPHP5Scanner`
- Add unit tests for the scanner
@junichi11 junichi11 linked a pull request Dec 23, 2024 that will close this issue
@junichi11
Copy link
Member

@Wukkopi It would be nice if you can test a dev version: https://github.com/apache/netbeans/suites/32363378994/artifacts/2354210960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants