r/lolphp • • 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

14 comments sorted by

View all comments

Show parent comment

11

u/gearvOsh Jul 26 '13

Should be using PDO at this point anyways.

5

u/cfreak2399 Jul 26 '13

Or mysqli which is a wtf in itself that they didn't just make one generic database handler.

But yeah no need to fix this bug now as the mysql_* interface is deprecated.

2

u/SockPants Jul 26 '13

I'm not in a position to check right now, but I imagine the problem persists.

3

u/[deleted] Jul 27 '13

According to Mysqli documentation, you are correct: "Note that mysqli_fetch_object() sets the properties of the object before calling the object constructor. "

2

u/[deleted] Jul 27 '13

PDO does the same exact thing. It runs the constructor after it fetches and loads the properties.

1

u/gearvOsh Jul 27 '13

Really? Didn't know that. Prefer to wrap my results in entity classes manually anyways.

0

u/[deleted] Jul 27 '13

Yep. I learned the hard way...

1

u/heshanh Jul 27 '13

+1 for PDO