PHP Rabbit Holes [solved]

Whoa.

  1. Got tracks to work (with laptop not at home).
  2. Destroyed tracks by attempting to “fix” or improve it (with laptop still not at home).
  3. Fortunately, I hadn’t pushed anything to GitHub yet so, at home on my iMac, got tracks to work again … with a bit of ghost code “product” appearing in the browser with my returned data.

After my success with albums, I then got tracks to work. The loop(s), however were sending 36 requests (one for each album). What I wanted, however, was to combine all the tracks from all albums into one array, then divide them by 50 so there were nine arrays and, thus, only nine requests. So I started to “fix” it.

That’s when the madness began.

Insanity #1: After much debugging and profanity, I realized that instead of putting tracks into the arrays like this …

  • 50
  • 50
  • 50
  • 50
  • 50

and so on, it was doing this …

  • 50
  • 100
  • 150
  • 100
  • 50

At first I thought the numbers were only going up but then realized they were going up then down. It did this while using array_slice despite the start and stop variables echoing the correct numbers … and that’s just one bit of weirdness with numbers/calculations not making sense. One of the other bits of weirdness is back when the tracks script worked (meaning it got everything even if it took “too many” requests for my standards of elegance) the variables for start and stop in the array_slice were not correct — they weren’t incrementing at all.

Still don’t think figured that out but it may be related to …

Insanity #2: After giving up on solving and fixing that (I just accepted the idea of 36 requests for the time being), one of the echo commands I used from a previous version of madness still appeared …

You have made 0 getTracks requests

Two things about that:

  • The line of code with the echo no longer exists.
  • The line of code setting the variable the echo refers to no longer exists.

Honestly, I don’t remember googling “super globals” or even “php globals” or why I thought of those but I’ve since learned, so far, that they, apparently, are stored in either php.ini or some other php config file … so me deleting the line of code in my script may not have gotten rid of the variable? Maybe? Let’s assume that’s true. That explains my second bullet above — why the variable still exists — but it doesn’t explain how or why the echo command still … “exists”(?) … somewhere …

INSERTED UPDATE: The above theory about the $GLOBALS being stored somewhere is just as false and nonsensical as I knew/hoped it was. See end of post.

It can’t be the cache because I did the destruction on one computer and re-did the progress with tracks on a different computer. The code related to the “ghost” feedback never existed on the iMac and I never accessed the “broken” files from browsers on the iMac. The ghost is in the remote machine.

Seriously, PHP has been creeping me out for about 18 hours. I had dreams about it. For real. I also had dreams about multiple wives and multiple ex-wives and the Chinese successfully invading the USA though those may have been subconscious metaphors for the PHP weirdness. Or metaphors or prophecies having to do with something else entirely.

More to come.

P.S. What worries me is, in troubleshooting, I thought I should make more $GLOBALS variables of things in loops so I could unset them, but … so … who knows what supernatural, ancient, Lovecraftian, Raimian, code gods I’ve unleashed …

Update #1: Read entire php.ini file and there’s no mention of the $GLOBALS array. The other super globals are mentioned.

Update #2: Insanity #2 was totally my fault. That actually makes me feel much better. There is currently a total of five files in this little app. Here at home, I was only changing and uploading two of them but the two lines of code also appeared (I was using that echo and variable in multiple locations for debugging purposes) in a third file.

Insanity #1 still haunts me.

UPDATE #3 on Nov 8: Insanity #1 [solved]

I was basing my array_slice on how I did it in Javascript so it looked like this:

$x = ceil((count($artistAlbums))/20);
$firstAlbum = 0;
for ($i=0; $i<$x; ++$i) {
$lastAlbum = $firstAlbum + 19;
$artistAlbumsChunk = array_slice($artistAlbums, $firstAlbum,     $lastAlbum);
$albumsArrays [] = $artistAlbumsChunk;
$firstAlbum += 19;
};

I was interpreting the offset parameter as “first” (accurate enough) and the length parameter (because I wasn’t paying attention when I read the documentation) as “last” like it is in Javascript.

Advertisements

About jotascript

Aiming to please. Seeking to impress.
This entry was posted in Debugging, PHP. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s