Skip to content

Conversation

@adamaveray
Copy link
Contributor

Adds support for PHP 8.4 property hooks, specifically addressing the parser issue being triggered for property hooks on interfaces.

This is the syntax that this PR adds support for: https://psalm.dev/r/6e926c6c01

Closes #11452.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/6e926c6c01
<?php
declare(strict_types=1);

interface TestInterface {
  public string $test { get; }
}

class Test implements TestInterface {
  public string $test = 'Hello world.';
}

print_r(new Test()->test);
Psalm output (using commit cdceda0):

ERROR: ParseError - 5:3 - Interfaces cannot have properties

@davidbyoung
Copy link

Hey @danog, is there anything else needed to be able to merge in this PR? Without it, we cannot use Psalm on all PHP 8.4 codebases. Thanks!

@DocFX
Copy link

DocFX commented Dec 7, 2025

I firmly do approve this PR! :) #needed

@DocFX
Copy link

DocFX commented Dec 24, 2025

+1 @danog this is getting really of a blocker now :/

@danog
Copy link
Collaborator

danog commented Dec 26, 2025

Thank you, awesome!

@danog danog added the release:feature The PR will be included in 'Features' section of the release notes label Dec 26, 2025
@danog danog merged commit ca6e171 into vimeo:6.x Dec 26, 2025
4 checks passed
@adamaveray adamaveray deleted the support_interface_property_hooks branch December 27, 2025 13:56
@kkmuffme
Copy link
Contributor

kkmuffme commented Jan 4, 2026

@danog did the tests pass without errors? Because now the CI fails due to issues from this PR (e.g. MissingConstructor,...), see also https://psalm.dev/r/25761f9365 (nvm the first 3 that's bc of PHP 8.2 on psalm.dev)

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/25761f9365
<?php

                    interface I {
                        public string $name { get; set; }
                    }

                    class A implements I {
                        private string $_name = "hello";

                        public string $name {
                            get => $this->_name;
                            set => $this->_name = $value;
                        }
                    }

                    function test(I $rw): void {
                        $rw->name = "test";
                        echo $rw->name;
                    }
Psalm output (using commit cdceda0):

ERROR: NoInterfaceProperties - 17:25 - Interfaces cannot have properties

ERROR: NoInterfaceProperties - 18:30 - Interfaces cannot have properties

ERROR: ParseError - 4:25 - Interfaces cannot have properties

ERROR: MissingConstructor - 10:39 - A has an uninitialized property A::$name, but no constructor

@adamaveray
Copy link
Contributor Author

@danog did the tests pass without errors? Because now the CI fails due to issues from this PR (e.g. MissingConstructor,...), see also https://psalm.dev/r/25761f9365 (nvm the first 3 that's bc of PHP 8.2 on psalm.dev)

Just FYI this PR (and the original issue it was addressing) was regarding support for properties on interfaces, not class property hooks. If Psalm is failing on those then that would need a separate issue.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/25761f9365
<?php

                    interface I {
                        public string $name { get; set; }
                    }

                    class A implements I {
                        private string $_name = "hello";

                        public string $name {
                            get => $this->_name;
                            set => $this->_name = $value;
                        }
                    }

                    function test(I $rw): void {
                        $rw->name = "test";
                        echo $rw->name;
                    }
Psalm output (using commit cdceda0):

ERROR: NoInterfaceProperties - 17:25 - Interfaces cannot have properties

ERROR: NoInterfaceProperties - 18:30 - Interfaces cannot have properties

ERROR: ParseError - 4:25 - Interfaces cannot have properties

ERROR: MissingConstructor - 10:39 - A has an uninitialized property A::$name, but no constructor

@jorgsowa
Copy link
Contributor

jorgsowa commented Jan 6, 2026

(nvm the first 3 that's bc of PHP 8.2 on psalm.dev)

@kkmuffme based on the message, the last commit used in Psalm Sandbox is cdceda0

@danog, could you please release new version containing this PR? It's bigie and 6.14.3 doesn't contain it.

kkmuffme added a commit to kkmuffme/psalm that referenced this pull request Jan 7, 2026
Fix failing tests from github.com/vimeo/pull/11569
kkmuffme added a commit to kkmuffme/psalm that referenced this pull request Jan 7, 2026
Fix failing tests from github.com/vimeo/pull/11569
@kkmuffme
Copy link
Contributor

kkmuffme commented Jan 7, 2026

These tests added by this PR:

InterfaceTest::testValidCode with data set "interfacePropertyWithGetHook"
InterfaceTest::testValidCode with data set "interfacePropertyWithBothHooks"

both fail with MissingConstructor just like on psalm.dev... (I "fixed" in 31fc5d0)

Additionally shepherd/psalm fail with

Error: src/Psalm/Storage/PropertyHookStorage.php:16:17: PossiblyUnusedProperty: Cannot find explicit references to property Psalm\Storage\PropertyHookStorage::$is_final (but did find some potential references) (see https://psalm.dev/149)
Error: src/Psalm/Storage/PropertyHookStorage.php:21:17: PossiblyUnusedProperty: Cannot find explicit references to property Psalm\Storage\PropertyHookStorage::$by_ref (but did find some potential references) (see https://psalm.dev/149)
Error: src/Psalm/Storage/PropertyHookStorage.php:23:26: PossiblyUnusedProperty: Cannot find explicit references to property Psalm\Storage\PropertyHookStorage::$location (but did find some potential references) (see https://psalm.dev/149)

all of which were added by this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature The PR will be included in 'Features' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.4 property hooks on interfaces cause parse errors

6 participants