[php-src] Issue #8152: Cannot hydrate a DateTime instance created without the constructor
| From: | derickr | Date: | Thu, 07 Apr 2022 11:00:28 +0000 |
| Subject: | [php-src] Issue #8152: Cannot hydrate a DateTime instance created without the constructor | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240737@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8152
Comment Author: derickr
Some historical perspective:
- These properties were never meant to be public — as setting these would imply that they would
modify the underlying data (they don't).
- They were added to be displayed for debugging and tests (through
var_dump() and
friends).
- Somebody later added serialisation support, and __wakeup() etc.
- Using __wakeup() to magically make the DateTime properties do something
is IMO also a hack.
None of the DateTime* classes should have publicly writable properties, and the right
way to hydrate these objects is/was by using __set_state.
I do find it odd that Foo::__set_state() wouldn't return a Foo class
though, and I think I consider that a bug. There is however no other built-in class that implements
__set_state() in the standard distribution.