nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

Extract fails on array properties with class constant keys #143

Closed kynx closed 11 months ago

kynx commented 12 months ago

Version: 4.1.1

Bug Description

If a class property is an array and the default value uses class constants as keys, extracting the class throws a TypeError: Illegal offset type

Steps To Reproduce

    class Class1
    {
        public $constKey = [self::class => 'foo'];
    }

Expected Behavior

The property is extracted.

Possible Solution

This was broken by something around https://github.com/nette/php-generator/commit/d915b7fa643cd0cf6ffe306c25ac5c3db24914a4#diff-634a48b3c9efd3101dad0b38a2be84c212cdf9d9e73246cf36de82e6e26a876eR424-R426

I'll do a PR with a test to reproduce and see If I can figure out a fix.