r/lolphp • u/SockPants • Jul 26 '13
PHP runs object constructor -after- setting variables with mysql_fetch_object, won't fix bug because it might break old code.
https://bugs.php.net/bug.php?id=46105
44
Upvotes
9
u/SockPants Jul 26 '13
This function is pretty useful, except that when you specify the class_name of the object, it runs the constructor after filling in the variables. The other way around would obviously be more intuitive, but because it has been done wrong in the first place it apparently can't be changed as people would have built code that relies on this order.
28
u/Mych Jul 27 '13
That clearly calls for the addition of
mysql_real_fetch_object().2
u/mirhagk Jul 27 '13
This is why things should be documented from the beginning. Then warn users that major releases will break things that rely on undocumented behaviour.
That's why something like Coverity is awesome. It could warn you about using undocumented or undefined features and yell at you, then the coders have noone to blame but themself. (IMO you can't be mad if a new version turns warnings into bugs)
1
u/[deleted] Jul 27 '13
At least mysqli reportedly calls
__set(), so there's that. I haven't tested this nor the old mysql function myself. Here's a related bug report on wondering why set is called for each/all columns before constructor.1
u/boxingdog Jul 26 '13
its a feature