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

Add failing test for array #51

Closed Nek- closed 4 years ago

Nek- commented 4 years ago

Hello, I found this bug :(.

dg commented 4 years ago

I can't see it.

Nek- commented 4 years ago

@dg what can't you see? (the test failure is not good enough for you?)

I was not able to make a good fix for it :/.

JanTvrdik commented 4 years ago

The current behavior is intentional. See https://github.com/nette/php-generator/blob/fd5e55cdd652efbce5878a4d56584059bd9b0802/src/PhpGenerator/Dumper.php#L102

Maybe there should be an option to disable this?

dg commented 4 years ago

Ok I get it. But it's not a bug, just a cosmetic thing because [606990006 => 'bar', 606990007 => 'baz'] is the same as [606990006 => 'bar', 'baz'].

Nek- commented 4 years ago

@dg absolutely. But this is also assuming PHP behaves like that, which is weird. And I think all weird stuff should not be considered as "this is good".

Of course, it's also extremely disturbing for people that will use generated classes, that's mostly why I'm suggesting to support this.

An option is probably the better idea, yes :).

dg commented 4 years ago

I would not call it a weird, it is a documented standard behavior that I like to use, for example in $months = [1 => 'January', 'February', 'March', 'April', 'May', 'June', ...]. But I understand that in the dumps where most keys are present, the missing ones are confusing.