Jeremy's Blog

Tag: Programming

PHPUnit support in PHPEdit

by Jeremy on Mar.31, 2007, under Uncategorized

I’m really starting to get disappointed in PHP IDEs. Because, I find one that works really well that I love (Zend Studio) but it falls short in respect of two things. The first being the lack of the ability to add support for other source control systems besides CVS and SVN. Second being the lack of built-in support for Unit Testing.

PDT (the Eclipse plugin) is very project-based. It offers up a lot of features that Zend Studio offers, with the added bonus of being built into Eclipse. And Eclipse has a plugin to support the Source Control System we use at work. Eclipse also has a plethora of other very useful plugins, like Aptana. PDT, unfortunately, offers no code inspection support for files outside of projects. That’s a bummer, because I have to jump in and out of various files in various locations that may or may not be apart of any project. So, PDT is missing ZDE staples, but has the benefit of being an Eclipse plugin, meaning I can have my source control integration.

Enter PHPEdit, which I’ve never used, but just learned that it’s going to solve the other problem, in an upcoming version. But not the first. I probably won’t use PHPEdit, except maybe to play around with, but the Unit Testing support is intriguing. If Zend Studio or PDT could get this in, that would be great. If Zend Studio could get this and alternate methods of adding source control support, that would be even better. I’m still waiting to see if PDT will be able to replace Zend Studio or not. Lately, I’ve been using them rather interchangeably, but I’m really wanting to move back to Zend Studio… Time will tell, but I wish these IDE developers would get it together.

3 Comments :, , more...

Running PHP6 in WAMP

by Jeremy on Feb.07, 2007, under Uncategorized

I’ve been wanting to start using PHP6 snapshots as part of my development process to ensure that my work (especially the Engine) is forward-compatible with the changes being made across the PHP Core. So, I set out on a little endeavor to make the PHP6 snapshots work in WAMP.

First, you’re going to need the latest version of WAMP. So, go to the site using the link above and grab the download. Now, my change is based on the PHP 4.4.4 Add-On (also, don’t install this Add-On if you want the switch to work properly), so it’s pretty simple to do.

Go grab the latest Win32 6.0-dev Snapshot from snaps.php.net. You’re going to need to extract this into your wamp directory as “php6″ so that you’ve got <path_to_wamp>\php6\php6apache2.dll … Now, copy the php.ini-dist file into <path_to_wamp>\Apache2\bin\ and rename it to php6.ini. You’re also going to want to open this file and change your extension_dir to <path_to_wamp>/php6/ext/ …

Now, save this file into your <path_to_wamp>\scripts\ directory as switch.php … You may have to modify this file to change the line:

$mphp6 = “php5_module”;

to

$mphp6 = “php6_module”;

This tripped me up last night, because php6apache2.dll was still registering as php5_module as of last night’s snapshot. I poked the internals mailing list and found this out from Antony Dovgal, who also said that this should be fixed in the next snapshot. I haven’t tested this to see if it has been fixed yet, though.

Anyway, after you’re done with all of the above, fire up WAMP and then open the command line. cd to <path_to_wamp>\scripts\ and then php switch.php (assuming you’ve got a path to a PHP binary in your system path — if not, you’ll need to use <path_to_wamp>\php\php.exe switch.php). This should shutdown Apache and swap out the PHP5 data for your PHP6 data. After it’s complete, and Apache restarts, check your phpinfo() and you should see PHP 6.0.0-dev.

And that’s all there is to it. :)

1 Comment :, more...

Floating Point Craziness

by Jeremy on Jan.03, 2007, under Uncategorized

I was just going through my RSS Feeds and I stumbled upon 81.4 is evil through Planet PHP. I invite all of you developers to try this for yourself.

The original code:

<?php
$total = 100 – 81.4;
//$total should be 18.6
echo “18.6 == {$total}? ” .
($total == 18.6 ? ‘yes’ : ‘no’) .
“\n”;
var_dump(18.6 – $total);
?>

You’ll get a “no” and var_dump will give you float(-7.1054273576E-015) … Talk about the precision being a little awkward.

Now if you thought that was weird, check this out.

Look at what happens when you type-cast $total to a string before doing the arithmetic:

<?php

header(”Content-Type: text/plain”);

$total = 100 – 81.4;
echo “18.6 == {$total} ? ” . ((string) $total == 18.6 ? ‘yes’ : ‘no’) . “\n”;
echo (string) $total – 18.6;

?>

For me:

18.6 == 18.6 ? yes
0

Does type-casting float variables to strings before performing the math actually increase floating point precision, in PHP? I found this kind of odd …

3 Comments : more...

PHP 5 Gotcha’s

by Jeremy on Sep.17, 2006, under Uncategorized

For a good portion of the day, I’ve been working with friend and co-worker Steven Harris on some new PHP 5 code. We’ve uncovered a few “Gotcha’s” that I think it would be best to share with everyone so that you won’t be as infuriated as we were about this whole thing.

First of all, and this is completely unrelated, if you’re doing tests with cookies, don’t allow your cookies to be set with “localhost” as the domain if you’re testing locally. I wasn’t aware before now that this didn’t work as intended, so there was a lot of headache with some code we’ve been fighting with.

Update: By the way, another co-worker recommended Microsoft Fiddler to me for debugging HTTP Traffic, and that’s how I rooted out the above problem. It’s definitely a wonderful tool, and I recommend it to anyone who might need to see exactly what’s getting passed over HTTP. There is one downside to it, though. It only works with Internet Explorer.

Our first PHP 5 Gotcha: Removed the E_STRICT deprecation notice from “var”. (PHP 5.1.3 Changelog)

This one tripped us up pretty badly today. Of course, it’s probably our fault for not reading the changelogs, but this was a bit of a nuisance. For a good long while I thought our error handler just wasn’t catching or passing errors along like it should’ve been, because we weren’t getting the E_STRICT deprecation notices that we’ve all come to love and adore. I wish someone would do me a favor and tell me why this notice was removed. Logically, it doesn’t make sense to me.

Next PHP 5 Gotcha: If date.timezone is not set in php.ini, you get an E_STRICT notice

I know this is desired functionality, but let me take a moment to let you know why this “got us” … And it has a lot to do with the above Gotcha. (And honestly, I’m kind of glad this notice exists, because it proved that my code wasn’t broken. ;) ) I’m going to just borrow Steven’s words here:

[23:07] Jeremy: Correct me if I’m wrong, but shouldn’t gmdate() NOT throw that timezone E_STRICT message?
[23:08] Steven: It would be stupid if it did, since there’s really only one timezone it should be concerned about, unless it needs current timezone info to get a difference (but that should already be handled by the OS)

Ways to circumvent this notice? Use date_default_timezone_set() if PHP >= 5.1. The date.timezone ini setting can also be changed at runtime, so use it if you’re on PHP < 5.1.

Our third and most annoying Gotcha: PHP bails out with class declaration nesting error when an error handler dynamically loads an error handling class during a class related E_STRICT warning. (PHP 5.1.1 Bug #35634)

Steven was testing on PHP 5.1.1 when we first started working on this code, and he caught this little gem. Luckily, the code we’re working on has support for text-only errors (it was loading the UI class that caused it to bail), so we may have to resort to that on PHP 5.1.1 (and possibly other versions, but I haven’t heard of this in any other version, so far), which would be a little annoying, but we’ll just have to deal with it, I guess. I’m also looking for an alternative work-around which I’ll share if I find anything.

Update 2: By the way, now that I’m looking over the code, it seems like Gotcha #2 is actually causing this problem for us. I’m going to see about fixing it to see if it fixes this problem, as well.

That’s all for now. I’m sure I’ll probably put some more together as we continue coding.

Note to self: Start reading the PHP Changelogs very closely and very often.

Comments Off : more...

Binary Math

by Jeremy on Aug.30, 2006, under Uncategorized

… oh, excuse me. I got side-tracked. Opened up the Wordpress Admin, and something else caught my eye. Anyway, down to business …

My last article, A Wise Bit (defunct), very vaguely touches on the concept of Binary Math. Afterwards, a few people who read this for the first time asked me about Binary Math because they were a bit confused. For the rest of you who may be interested, I directed them to the Wikipedia Entry. This is where I learned how Binary Math works, and I recommend it for anyone who’s looking to see how the Bitwise Functionality really ticks.

2 Comments : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!