Calling __toString() on FileUpload class directly can often result in type/uninitialized typed property error
finwe opened this issue · 1 comments
Version: 3.2.4, 3.3.0
Bug Description
When a file is not uploaded in a form, an empty FileUpload with uninitialized properties is returned to the Presenter. Once the data is processed by underlying code, by calling the __toString()
method on the object, which is typed as returning string, it will, based on version, either end on null returned, expected string
, or $tmpName must not be accessed before initialization
Expected Behavior
The method that should return a string returns a string.
Possible Solution
- Initialize the properties of FileUpload with values, namely $tmpName with empty string
- Alternatively make the properties nullable and initialize with nulls
- Cast the $tmpName to string in the toString method so that no error is thrown.
Happy to prepare a PR once I know what the preferred solution is.
The uninitialized FileUpload is completely stupid. I've had it in my TODO for like five years, so if you could fix the whole thing, that would be really cool. Or at least the __toString()
. Which way to solve it probably doesn't matter.