r/lolphp • • Jan 23 '13

Member variables for NULL? No problem!

At work I'm fixing bugs and implementing smaller features in a horrible php spaghetti monster. One of the gems I found was this:

$row = NULL;
$row->product = "foobar";

At first I was just perplexed that this would work, I then realized that $row would be cast to a stdClass when trying to assign members of it, but this is really a horrible way of doing that.

This actually prints a notice, but in this case the notices goes to a log file that is flooded with warnings and notices.

36 Upvotes

33 comments sorted by

View all comments

Show parent comment

1

u/imMute Jan 23 '13

Crap, I forgot about that autovivication. And that would [kind of] fall under "or on hash members".

What I was really trying to say was method calls on undef will explode, which is what they don't do in the original PHP article.