-
Notifications
You must be signed in to change notification settings - Fork 7.8k
DatePeriod can crash if passed non initialized DateInterfaces #11416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
|
That's my reaction too. This also happens with subclasses that do not call the parent constructor. The All objects check if their constructor has been called before accessing their internal state (like this in ext/date, but that's not specific to ext/date) and throw an exception otherwise, but it's easy to forget about adding this check, especially when the object is not $this. |
Right, that's even harder to catch... I wonder if it would be acceptable to disallow |
One way to prevent this currently is to declare a class as final and not-serializable. This disallows However, this may break some use-cases. E.g. test mocks or lazy objects rely on being able to sub-class and to not call the constructor. Mocking date objects is probably not a good practice, but there may be good reasons to mock some classes like PDO in tests. |
For PHP 8.1 and up: #11919 |
… passed in (PHP 8.2+)
… passed in (PHP 8.2+)
… passed in (PHP 8.2+)
… passed in (PHP 8.2+)
… passed in (PHP 8.2+)
Description
Found these while working on lazy objects.
The following code snippets result in crashes:
PHP Version
PHP 8.1
PHP Version
PHP 8.2
Operating System
No response
The text was updated successfully, but these errors were encountered: