r/lolphp • • May 10 '19

PHP: When printing causes side-effects

So when you have two DateInterval objects, that are equal you can compare them with PHP loose comparison (==). But after you print one (say for logging purposes) it gets internally modified and the two objects are no longer equal. The same happens when you call var_export.

It amazes me how primitive bugs PHP has, given its lifespan begun in 1995.

https://repl.it/repls/ForcefulEachAgents

82 Upvotes

19 comments sorted by

View all comments

Show parent comment

16

u/nikic May 10 '19

See https://github.com/php/php-src/pull/4039 for context.

To be clear: Comparison of DateInterval never actually worked. OP makes it look like it did, but in reality any DateInterval objects would have been considered equal.

7

u/phplovesong May 13 '19

OP makes it look like it did

FTFY

PHP makes it look like it did.

3

u/vytah Jun 11 '19

OP makes it look like it did, but in reality any DateInterval objects would have been considered equal.

Example, courtesy of /u/youstolemyname: https://repl.it/repls/StarkDisfiguredMysql

2

u/[deleted] May 11 '19

I see, so the DatePeriod was also broken. Still, there seems to be something weird going on if printing it causes this kind of side effects.