kphp icon indicating copy to clipboard operation
kphp copied to clipboard

Do not remove empty default values for string and array respectively

Open soloth opened this issue 1 year ago • 0 comments

Before this PR empty values are eliminated for string and arrays, so

class User {
  public string $name = '';
  public string $password = '';
}

and

class User {
  public string $name;
  public string $password;
}

are treated as same.

While it is true technically, this lead to unwanted consequences. Value absence marks such fields as required during JSON deserialization. Removed default value changes class semantics and has strong implication of string having default value of ''.

Suggested changes are about storing fact user provided value was optimized and eliminated. But the fact it was there is used by later steps to correctly process values.

soloth avatar Jun 25 '24 09:06 soloth