First, I'm not that familiar with package management on Fedora, so perhaps someone else can check the commands I've listed below.
On Debian, there are (at least) two different PHP packages:
php5-cgi - server-side, HTML-embedded scripting language (CGI binary)
php5-cli - command-line interpreter for the php5 scripting language
When you run your script from the command line, you're executing the second one of these. When you run your script via Apache, you're executing the first.
I've never known these to get out of sync - I've always seen both with the same version - but it doesn't sound like something impossible. I can imagine that if I really wanted to, I could figure out how to install different versions of both.
From my (limited) knowledge of package management on Fedora, I'd start by trying to update both packages to the latest version:
yum update php5-cgi
yum update php5-cli
Again, these may be named differently in the Fedora repositories, so you'll need to research that a little.