Skip to content

Instantly share code, notes, and snippets.

@samwho
Created April 22, 2011 15:21
Show Gist options
  • Save samwho/936870 to your computer and use it in GitHub Desktop.
Save samwho/936870 to your computer and use it in GitHub Desktop.
Email regarding PHP notice bug.
Okay, I've made significant progress on understanding the nature of this error.
It's, at its heart, very simple. $post->user->other is an array, not an object. Accessing it like an object was a very costly oversight on my part. It isn't tested for, either, because it was never a problem on my server and I'll explain why:
Take this script:
<?php
ini_set('display_errors', '1');
$object1 = new stdClass();
$object1->other = array('stuff' => 2);
if (isset($object1->other->not_existing_property)) {
echo "Lolfail";
}
?>
The if statement is the important part here. That's checking if a non existent property is set. As you would expect, this returns false (on both my PHP 5.3 local install and AngeloStavrow's Dreamhost 5.2 install (many thanks to him for helping me with this!)).
This is the offending line on the white house server (lines 645, 646, 647):
if (isset($post->user->other->avg_tweets_per_day)) {
$post->user->avg_tweets_per_day = $post->user->other->avg_tweets_per_day;
}
Line 646 is what's throwing the notice. The only way this could happen is if the conditional evaluates to true. Seeing as $post->user->other is an array, this should never be the case. In the white house server output, users do have an "avg_tweets_per_day" in their output that's always null, it seems. This fits with the isset() line evaluating to true and the PHP notice failing (as you'd expect).
So it seems that, for some reason, isset() is treating the last section of $post->user->other->avg_tweets_per_day is an array accessor but then failing to recognise it during assignment. I have no idea why. Any PHP guru's got any ideas?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment