Negative number PHP array indexes, var_export and WTF

Those folks that know me in the programming, web development or technology context know that I am a PHP fanboi to the nth degree. I eat, sleep, breath and live PHP. It is my very favorite programming language and it is the language that I learned how to program in. I stand behind it and have defended it – often – against the attacks of many a strict-type-language zealot from the world of .NET or Java or even Ruby. Seriously, I love PHP with all of $my <3;

However, these same people that know my insane and indescribable love for "my" language also know that I am usually very fast to point out some of it's major stupidities and illogical implementations. Which comes first, the $haystack or the $needle? Is it a str_* function or a str* function? Are the array function args passed by reference or am I expected to handle a return? There are so many of these little issues with PHP that sometimes I, myself, have no choice but to ask... WTF?

Today is one of those days. I am working on a bug for work in which the number -99 is somehow magically being transformed into -9223372036854775808 and is causing significant problems for our application. In doing some trouble shooting, I discovered that, as part of our process of caching some information, we use the var_export() function to write out an array to a file and somewhere between the passing of the data to var_export and the file that the exported data is written to, the -99, when used as an array index, suddenly became 18446744073709551517. This did not happen when -99 was the value of a scalar variable nor when it was a value assigned to an object property.

Looking a little closer I found that this particular server was running PHP 5.2.17 on CentOS, so I decided to dig even deeper and try this on other versions of PHP. On my 5.3.6 version of PHP on my Mac I could not reproduce the issue. But I was able to reproduce it on 5.2.17 on my Mac. My colleague was likewise able to reproduce it on 5.2.10 on his Ubuntu installation. And I was able to reproduce it on several PHP versions using 3v4l.org.

I'm not exactly sure what is going on under the hood, but my suspicion is that because PHP does not support unsigned integers it needs to convert the signed int -99 to an unsigned value in order to store it in the symbol table. I suspect when var_export is called, this unsigned value is being returned rather than the signed value. At the very least, this is an issue that will more than likely never be corrected since PHP 5.2 is now out of date and this problem, as far as I can tell, does not expose itself in 5.3 save for 5.3.3.

Regardless, if you want to see this for yourself and you have a 5.2 build laying around somewhere (or a 5.3.3 build), give this little snippet a shot and see what you get:

<?php
for ($i = 10; $i > -101; $i--) {
    echo "$i...\n";
    $q = array($i => 'this');
    var_export($q);
    echo "\n";
}

Or, if you just want to see it without a bunch of output, try this:

<?php
$a[-99] = 'bilk';
var_export($a);

As an added bonus, take the broken translated value and use that as an array index, then var_export that. You might pleasantly surprised by what you see I'd bet.

All of this is to say, if you are still using PHP 5.2 - and let's be honest, who is really using PHP 5.2 any more aside from those that have it on a test server - and you are using var_export on an array with signed int indexes, you are probably not going to get what you expect out of it. You have been warned.

Also? WTF PHP?

Never try to change anything using WordPress.com

A few weeks ago I learned of a cool little statistics package that you can install on your WordPress blog that does a really good job of managing your stats. So I installed it here on this blog to see what people are searching for, reading and generally interested in and tied it an API key from WordPress.com account that I have used for my Akismet (anti-spam) plugin.

A few days later I realized that the WordPress.com account I have been using for Akismet was tied to my old business profile name, Everah, and not my newer, more open identity of RobertGonzalez. So I decided to change the API key I am using for Akismet and Stats to the API key for my personal account rather than my business account. And that, my friends, is wherein my biggest pain in the butt for the last two weeks has resided.

It started with the fact that there is really not a clear set of instructions for changing your Stats API key. Unlike Akismet, where you can go to Plugins -> Akistmet Configuration from inside your admin panel and change your API key, Stats requires that you deactivate it as a plugin first, then reactivate it then go through all the rigmarole of setting it all back up again. After finding the instructions to do that – thanks to Google and a lot of pissed of WordPress.com Stats users – I deactivated the plugin and reactivated it again, setting it up this time with my personal API key. Which, in my case didn’t, seem work.

So after playing around with this forever I decided that it was time to submit a help ticket to the WordPress crew. The context of the ticket was pretty simple, I wanted to swap API keys between my personal and business accounts on their end, which in my opinion, would have been the easiest thing to do. Their support response, looking back on it now, were actually pretty good, except they did not answer my questions and actually led to more questions on top of the ones I had. When you get to the end of it all you will see that their initial suggestion (or second one) is in fact what I ended up doing. But it was a nightmare going through all of this.

The following is the transcript of all of our conversations (skip this and continue on the other side of it):

from: Anthony – WordPress.com
to: robert@robert-gonzalez.com
date: Sat, Feb 7, 2009 at 7:15 AM
subject    [WordPress #252013]: General – That I really only need one. But I cannot merge th

Hi,
You cannot move API keys around. If you wish for us to transfer a blog to a different account, we can do that: http://support.wordpress.com/moving-a-blog/#transferring-your-blog-to-another-user-or-account

Best,
Anthony
Automattic | WordPress.com

from: Robert Gonzalez
to: support@wordpress.com
date: Sat, Feb 7, 2009 at 10:05 AM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

What I really want is to use the API key and history from the “everah” account only have it under the “robertgonzalez” account. My self hosted blog has a pretty decent Akismet history from the API key associated with the everah account and I just installed the stats plugin. I really want to not have my self hosted blog associated with the “everah” account at all and would prefer to have everything run from the “robertgonzalez” API key.

Should I just abandon the history I have with the everah account and start all over with the robertgonzalez account?

from: Anthony – WordPress.com
to: robert@robert-gonzalez.com
date: Sat, Feb 7, 2009 at 10:51 AM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

Hi,
I can add the robertgonzalez account to the self-hosted blog’s access list from this end – so that it can access the blog stats. If this is what you would like, please verify the blog URL.

Best,
Anthony
Automattic | WordPress.com

from: Robert Gonzalez
to: support@wordpress.com
date: Sat, Feb 7, 2009 at 7:38 PM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

Does that mean if I switch the Akismet and WordPress.com Stats API key then the data that has been collected so far would transfer as well? What I really would like is to not lose the Akismet stats I have collected under the everah account. Both everah and robertgonzalez have the same email and same URL for the blog address (http://www.robert-gonzalez.com) which is my self-hosted blog.

from: Nick – WordPress.com
to: robert@robert-gonzalez.com
date: Wed, Feb 11, 2009 at 6:33 AM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

Hi,
The stats aren’t stored with the account, they are stored with the blog. So giving another user access doesn’t do anything to the stats.

Nick
Automattic | WordPress.com

from: Robert Gonzalez
to: support@wordpress.com
date: Wed, Feb 11, 2009 at 7:20 AM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

I tried that, switching the API key from the everah API key to the robertgonzalez API key and my stat count dropped from thousands down to 8 for akismet. Both accounts have my self hosted blog url registered to it. That is why I thought that switching was going to cause stat trouble.

So if I change the API key then theoretically nothing should change as long as the blog is registered to the account?

Robert

from: Nick – WordPress.com
to: robert@robert-gonzalez.com
date: Wed, Feb 11, 2009 at 7:45 AM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

Correct. You mention Akismet, but Akismet isn’t blog stats, it’s for blocking spam on your blog.


Nick
Automattic | WordPress.com

from: Robert Gonzalez
to: support@wordpress.com
date: Wed, Feb 11, 2009 at 8:56 AM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

Right, by my akismet numbers changed too when I changed the API key which led me to believe that the API key was holding the stats, not the blog URL. Also, when I switched the API keys my stats basically vanished and I was told that I didn’t have access to the stats. I am guessing that had something to do with me being logged in to WordPress.com under everah while trying to hook into the robertgonzalez api key.

Really I just want everything to roll into one account: robertgonzalez. But I have history with the everah account that I want to make sure I don’t lose. If I need to massage the stats and akismet stuff though I guess I can.

Also, when are the developers of the stats plugin going to offer the ability to change the API key like Akisment does? Right now you either have to change the API key in akismet or, short of that, edit the wordpress_api_key config value to change it for stats.

from: Sheri – WordPress.com
to: robert@robert-gonzalez.com
date: Wed, Feb 11, 2009 at 4:42 PM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

Hi,
Akismet should work the same even if the numbers are different because it’s collective. Are you saying that spam is getting blocked differently if you switch the API key?

Also note that there is no way to look up Akismet stats on the wordpress.com system, so it really doesn’t matter which wordpress.com account you connect Akismet to from our point of view.

Sheri
Automattic | WordPress.com
http://support.wordpress.com/
http://en.forums.wordpress.com/

from: Robert Gonzalez
to: support@wordpress.com
date: Wed, Feb 11, 2009 at 5:03 PM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

What I am saying is right now, under Akismet stats, using the API key from the “everah” account, I see this:
4,396 spams caught, 228 legitimate comments, and an overall accuracy rate of 99.805%.

When I change my API key in the akismet admin screen to the API key for the “robertgonzalez” account, that line becomse something like:
8 spams caught, 0 legitimate comments, and an overall accuracy rate of 100.00%.

That is why I asked about the API keys. Also, when I switched the API key in akismet, the wordpress.com stats plugin seemed to go haywire. Like it didn’t know who I was or something.

I just want to make sure that the few days of stat harvesting and the last few months of akismet data harvesting doesn’t get whacked with a single change to the API key.

from: Sheri – WordPress.com
to: robert@robert-gonzalez.com
date: Wed, Feb 11, 2009 at 5:17 PM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

The data cannot be transferred between wordpress.com accounts. If you want to keep the same Akismet numbers showing in your blog, then you must use the first API key. If you want to change it, then it should not effect the future accuracy of the spam blocking, you will just see different numbers. It’s up to you if you whether to switch it or not.

When you change your API key for Akismet, it should not affect the stats. However, if you switch the API key for stats, make sure to select the “replace an existing blog” option in step 2.

Sheri
Automattic | WordPress.com
http://support.wordpress.com/
http://en.forums.wordpress.com/

from: Robert Gonzalez
to: support@wordpress.com
date: Wed, Feb 11, 2009 at 9:39 PM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

How do you unregister a blog from wordpress.com? I just tried switching API keys and I think since http://www.robert-gonzalez.com is registered to my “everah” account I cannot associate it with my “robertgonzalez” account. I keep getting this error when I input my API key:

WordPress.com Stats
Error from last API Key attempt:

Missing API Key

The WordPress.com Stats Plugin is not working because it needs to be linked to a WordPress.com account.

Enter your WordPress.com API key to link this blog to your WordPress.com account. Be sure to use your own API key! Using any other key will lock you out of your stats. (Get your key here.)

This is after I enter the API key and hit the “Add new blog” button. What do I do now?

from: Nick – WordPress.com
to: robert@robert-gonzalez.com
date: Thu, Feb 12, 2009 at 6:14 PM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

If you log into WordPress.com with the ‘everah’ account and then visit http://support.wordpress.com/contact/ to send us a request, we can change the owner of the WordPress.com stats for the domain. Make sure to let us know the domain name and the user you want to have access.


Nick
Automattic | WordPress.com

from: Robert Gonzalez
to: support@wordpress.com
date: Wed, Feb 18, 2009 at 10:53 AM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

I can’t submit a contact to you using the link below because the only blog attached to that account is my self hosted blog and your ticket system will not accept messages from blogs that are not hosted on your site.

This is a monumental pain in the ass. I really wish you would fix this. Seriously, it shouldn’t be this freaking hard to make a simple change.

from: Nick – WordPress.com
to: robert@robert-gonzalez.com
date: Thu, Feb 19, 2009 at 6:44 AM
subject [WordPress #252013]: General – That I really only need one. But I cannot merge th

There may be a bug in our system them. Because it should let you message us about a blog connected to our system through WordPress.com stats. Is the form giving you an error?


Nick
Automattic | WordPress.com

from: Robert Gonzalez
to: support@wordpress.com
date: Thu, Feb 19, 2009 at 9:40 AM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

Yes. Here are the steps I took:

1. Log in to WordPress.com using the account “everah”.
2. Go to http://support.wordpress.com/contact/
3. Fill out the form and leave the Blog URL field empty
4. Submit

Error: Let us know the URL of your blog.

I then select the only Blog URL that is on my account, http://www.robert-gonzalez.com and submit…

Error: We only provide support for WordPress.com blogs here. Please go to the WordPress.org Support Forum for further help.

from: Robert Gonzalez
to: support@wordpress.com
date: Thu, Feb 19, 2009 at 9:45 AM
subject Re: [WordPress #252013]: General – That I really only need one. But I cannot merge th

You know, I was just reading the tips above the form and #3 says:
We only support WordPress blogs hosted here on WordPress.com. If your blog is running the self-hosted version of WordPress, you should seek support elsewhere.

So dude, what the hell? Am I stuck in the position I am in?

Ultimately what I needed to do was remove this blog’s URL from my business account, where it was primary, and move it to my personal account as the primary blog. But I had to have some way of doing that so I could request it through their system. So I had to get crafty, tricksy if you will, so I could circumvent the stupid trouble ticket form on their web site. Wanna know how I did it?

What I finally ended up doing was creating a new WordPress.com blog under my “everah” username so I could submit a help ticket to the crew. I then logged into that account and sent them a trouble ticket in which I told them to reference this long string of emails that we vollied to one another and asked that they just move this blog’s url from one account to the other. Which is what they suggested in the first place.

They did it. And of course, now stats work properly, but Akismet is now down to nothing again, so I ended up going back to API key from my business for that. But at least stats are working. And at least I was able to get this situation mostly resolved. But if there is one thing I would suggest you never do, it is try to change anything on your own blog and then ask for help from the WordPress.com crew to make it happen smoother.

Asleep at the wheel

On my way home from work tonight I found myself in a scary position… I could not keep my eyes open at all. I have been tired before, and I have managed to drive my way through being tired before, but tonight was especially different. No matter what, it seemed I could not keep my eyes open or the car straight.

It wasn’t until about halfway home that I decided to put my earphones in my head, turn up the volume on some very loud rock music and open all the windows in the car so the 43 degree wind could do its work. And that managed pretty well until I got home. But it was a scary moment for me. For about 20 minutes or so.

My eyelids would not stay, plain and simple. No matter what I did my eyes kept trying to close. That went on for a few minutes then the yawns came and that seemed to make my eyelids even heavier. The more I tried to fight it the more it seemed that my eyes were on their own. It was pretty freaky.

Thank God I eventually snapped out of it. I made it home in one piece and as I pulled up in the driveway I felt very awake. But for a short period of time I thought that I might actually hurt myself, or worse yet, someone else by the way I was driving. I certainly hope I never have that happen again.

Perhaps, to make sure of it, I should go to bed at 9:00 tonight. What do you think?

How big is big?

Me: “I hate Internet Explorer. It can’t even handle large tables.”
Me: “Can a table get that large?”
He: “No, but a zucchini can.”
Me: “Dude, WTF?”

I turn around to see what he is talking about and BAM!, there is a big fat zucchini in my face. Shocked and awed at the sight of this thing, I could only pick it up and try to quell the thoughts that any man would have when faced with something this big.

A big zucchini is always fun

Ok, comments are open. Let me have it. I know you will anyway.

PS For those that care, the ladies around here named him “Zucchy” and promptly took him home and made bread from him. 🙂

A marriage that perhaps should not have taken place

Editor’s note: I know sometimes I write about some pretty stupid stuff here. And sometimes, like yesterday, I write about stuff that is a little personal. I hope I don’t give the impression that I am trying to air my dirty laundry in public. It is a pretty well know fact that all of about three people read this blog of mine and I am fairly confident that those three people either have had some experience with what I talk about when it comes to things like marriage or they simply don’t care what I write about. Either way, I am good with it. I find blogging to be wonderfully therapeutic and I know it is helping me get through a really tough time in my life.

Robert

Last night I had a good talk with my wife about our relationship and our feelings toward one another, toward our children and toward our God. While I have to say that most of the conversation was my wife telling me, in the form of “just some guy that is asking” how her marriage is holding up, I can say that I was able to get a lot of my chest. One thing, however, stuck out to me and I feel compelled to write about it.

One of the things that came up in our discussion was the topic of why my wife said yes to me when I proposed. The answer astonished me to a degree, though I am quite at peace with what was said. Essentially my wife told me that the reason she said yes to my proposal is because she didn’t know how to tell me no.

Regret is a terrible thing to live with, wouldn’t you say?

I know being married to me is no bed of roses. How could it be? After all, I am me and that in itself is enough to make anyone cringe. And I can say that I totally get her response to that. For the most part she has been miserable in our marriage since we got married. Scratch that, she has been miserable since we got back together in 1993 after breaking up for a few months.

But I can’t help but wonder how a person can stay married to someone they didn’t really want to marry and cannot find joy in being married to. My thought is divorce would be a much easier one-time miserable situation to live with than a lifetime of staring at your worst nightmare in the face. Wouldn’t it?

How crappy would it be to wake up every morning knowing that you are married to someone that you would much rather not be married to? Worse, what if every time you looked at that person you were reminded that for the last 13 years your life has been the worst it has ever been and it is all the fault of the person that you are sharing your life with?

So I asked these questions to my wife and her response was pretty simple. She is not a quitter. She would much rather be miserable in marriage than say that she gave up on it. Somehow trying to work through 13 years of a marriage in hell is redeeming when you can say that you stuck it out. I am not so sure.

Personally I am of the mindset that your marriage is what you make of it. You can make it crap or you can make it work. Regardless of what you want out of your marriage you are always at the helm of what your marriage experiences. You choose to say things, to do things, to feel things that have an impact on your relationship. I choose to make my marriage good or bad. So in effect, I have chosen to do things that have made my wife miserable in our marriage.

Sadly I am not at all aware in most cases of what I am doing or not doing that makes my wife miserable. In other cases I know that something I do has a negative impact on my wife but the thing that I do is a part of who I am as a person. No matter how hard I try to kill that part of me for her sake it always creeps back in and always has the same effect.

All of this leads me to the conclusion that looking back on 16 years of hell would almost certainly make a person want to stop the bleeding. How much misery can a person take? How long will a person choose to sustain their position in a relationship that reminds them of a 13 year (and counting) mistake they made? Wouldn’t it make more sense to count your losses and start afresh with half a chance at finding what you want in a person other than the bastard you are married to?

I hope I don’t come off as angry with this post. That is not the case at all. I am more than aware of how miserable my wife is in our marriage. I am in that same marriage with her. I see it and hear it every day. And as weird as it sounds, I really do want what’s best for my wife and children. I don’t want my wife to be miserable. I want her to have everything she expects to have in the man of her dreams. Hell, I want that sort of happiness too. So I am not mad to find out that I am not what my wife wants in a life partner. I just wish I could give her what she wants so she does not have to be miserable all the time.