Added My Bookmarks

Posted 2/12/2005 By Jason

I added my recent bookmarks to this blog under the calendar in the side bar. I googled for the basic plugin, and tweaked it a bit to suit how I wanted to use it.

The plugin looks like:


Plugin Name:
Plugin URI:
Description: Fetches your <a href=""></a> bookmarks list using the standard HTML method.
Provides one function, delicious().
Author: Phil Ulrich
Author URI:
function delicious($username='sweatje', $count=10, $extended="Bookmarks",
 $divclass="link", $aclass="storytitle", $tags="yes", $tagclass="meta", 
 $tagsep="/", $tagsepclass="delTagSep", $bullet="raquo",
 $rssbutton="yes", $extendeddiv="no", $extendedclass="")
    $cache = 'cache/';
    if (file_exists($cache)
        && false !== ($mtime = filemtime($cache) )
        && (mktime() - $mtime) < 3600) {
        echo file_get_contents($cache);
    $queryString = "";
    $queryString .= "$username/";
    $queryString .= "?count=$count";
    $queryString .= "&extended=$extended";
    $queryString .= "&divclass=$divclass";
    $queryString .= "&aclass=$aclass";
    $queryString .= "&tags=$tags";
    $queryString .= "&tagclass=$tagclass";
    $queryString .= "&tagsep=$tagsep";
    $queryString .= "&tagsepclass=$tagsepclass";
    $queryString .= "&bullet=$bullet";
    $queryString .= "&rssbutton=$rssbutton";
    $queryString .= "&extendeddiv=$extendeddiv";
    $queryString .= "&extendedclass=$extendedclass";

    $html = implode(' ', file($queryString));
    $data = str_replace(array('<div class="link">',''),array('<li>','</li>'),$html);
    // php5 only file_put_contents($cache, $data);
    $fh = fopen($cache, 'w');
    fwrite($fh, $data);
    echo $data;

Update: Per the comment from Darren, I added caching. I was on me “TODO” list, but you know how those go 😉


Spotted in the Wild

Posted 1/23/2005 By Jason

Here is a little teaser of something I spotted in the wild!!!


Google Vs. Blog Comment SPAM

Posted 1/19/2005 By Jason

Via the Ruby general list I stumbled on Preventing Comment Spam from Google. This seems like an easy enough idea; I will have to see if I can scrounge up enough time to hack it into WordPress.

On a related note, I heard that sometimes spammers actually have real people entering these inane blog comments. If so, I think they need some more training. 😉 It seems they are leaving obtuse comments without a url linked, and therefore with no purpose at all?!?


Euclid’s Algorithm in one line of PHP

Posted 1/14/2005 By Jason

Sometimes I am amazed at how forums work. The way in which people come and offer help, myself include, impresses me. I do not fully understand my own personal motivations for participating in forums, but at least one one of the reasons is sometimes the opportunity to write so code just for the fun of it presents itself. One such case was here. The original poster essentially wanted to reduce a fraction (though he was kind of beating around the bush about it). The post had been up on the board for a day, and several people had answered trying to help and clarify the issue at hand.

I dredged up some grade school math memories from long ago, and recalled the way to reduce a fraction was to identify the greatest common denominator, and divide each of the parts of the fraction by the gcd. I jumped to my reference page and located the Dictionary of Algorithms and Data Structures to search for greatest common denominator.

This quickly lead to Euclid’s Algorithm, a heuristic methodology for identifying the greatest common denominator. About a minute of thought later, I implemented the algorithm in a one line recursive function call:

function gcd($a, $b) {
  return ($b) ? gcd($b, $a % $b) : $a;

With that in hand, it becomes trivial to write the function to reduce the fraction.

So why am I blathering on about this? No particular reason, sometimes I just like the elegance of a particular solution, and this one struck me as one I wanted to mention and save for posterity. It is not an OOP solution, but being object oriented is not a requirement for elegance or utility. As a side effect, it was an opportunity to throw out some links that someone may end up finding useful.


New Job

Posted 1/4/2005 By Jason

Today the announcement came out at work regarding my promotion. I am now the eBusiness Manager for Alcoa Mill Products. My friend Robert Yoerger, was promoted from eBusiness Manager to Director / Customer Service, Demand Planning and eCommerce for AMP North America, and I am officially departing my IT role of Senior Project Leader to fill his vacated position as well as report to him.

This role is a gentle change from an IT role to a business role. I have always “over functioned” a bit in my IT role to assist in defining business process. Now my role explicitly demands this. I essentially have become my own customer. I still have two contractors reporting to me with strong SQL and Siebel skills (as well as developing PHP/web skills), and in addition, the eBusiness Marketing Staff Assisting will also report to me.

The biggest tasks on my plate this year are the need to upgrade our current version of Siebel CRM, and to maintain all of our existing commercial systems while we deploy a new Oracle order management solution at our largest facility. In the meanwhile, I also need to make sure our newly deployed Gentoo Linux intranet web server meets our internal audit standards and is SOX compliant.


Merry Seasonal Holliday

Posted 12/25/2004 By Jason

Twas the Night Before the Lawyers 😉


Yummy, Yummy,

Posted 12/22/2004 By Jason

I can’t believe it has taken me this long to play with My page is here. For anyone who is as slow and behind the times as me, is a public bookmark storage mechanism. As you bookmark pages, you can catagorize them into as many sections as you wish, and then can easily lookup those groups of links in your own list…or see what other people have bookmark in the same catagory on their lists.

To me, this seems to lead to a much more directed exploration than random browsing from google hits. The central idea is these are links that someone else has already felt there is enough merit to save and come back to again later.

In addition, I have re-discovered some old friends via common links. I found my friend Boots who had a facinating page on Quantum Mechanics. This is an interesting bit of seredipity, as I had recently asked one of my friends who is a Physics major for just such a summary, as I wanted to use some Quantum Chromodynamics Rules as the basis for “business logic” in a PHP article I was writing.


Chaining Object Calls in PHP4

Posted 12/17/2004 By Jason

I ran across a SitePoint post where a user wanted to chain calls to returned objects in PHP4, similar to what you can now do in PHP5. Of course PHP4 does not allow this syntax, but the user came up with the idea of calling a function with the base object, and the series of calls as a string argument. The function would then parse the string and apropriatly eval() the calls. I took his idea as a springboard, and re-wrote it to use recursion for arbitrary call depth.

Here are the functions:

function &chain(&$obj, $call) {
        return call_chain($obj, explode('->',$call));
function &call_chain(&$obj, $stack) {
        if ($stack) {
                eval('$new_obj =& $obj->'.array_shift($stack).';');
                return call_chain($new_obj, $stack);
        } else {
                return $obj;


And here is a cheesy example:
Read the remainder of this entry »


New PHP Releases

Posted 12/17/2004 By Jason

From the internals list. Downloads here. But a word of caution, I have heard grumblings of problems from people migrating to 4.3.10 on some message boards I follow.
Update: If you experience any problems with upgrading to PHP 4.3.10, make sure you have the latest Zend Optimizer if you are running it. It seems there are problems with older versions of Zend Optimizer and foreach().

PHP Development Team would like to announce the immediate release of PHP
4.3.10 and 5.0.3. These are maintenance releases that in addition to
non-critical bug fixes address several very serious security issues.

These include the following:

CAN-2004-1018 – shmop_write() out of bounds memory write access.
CAN-2004-1018 – integer overflow/underflow in pack() and unpack() functions.
CAN-2004-1019 – possible information disclosure, double free and
negative reference index array underflow in deserialization code.
CAN-2004-1020 – addslashes not escaping


Tan, Rested and Ready

Posted 12/7/2004 By Jason

Back from a weeks vacation in Acapulco…

Acapulco sunset ride with the kids
Family at the Mexican Fiesta!

and there is a lot on the table to look at…

  • The usual catch-up at work
  • Continued writing on my in-progress book (actually managed to finish a chapter on vacation!)
  • Marcus released some interesting object persistence code here to the public domain.
  • WACT had release 0.2a!!!
  • Marco has something new and warm in the works…
  • It looks like someone hacked my WordPress instance…need to figure out what is up with that :(

A week without the Internet is good for the soul, but bad for keeping current :)


Documenting External Dependancies

Posted 11/22/2004 By Jason

There is an issue which kind of bugged me with external dependencies in my source code documentation after it is parsed by phpDocumentor, the source code doc does not know much about the external libraries, and therefore leaves references to them dangling…

This particular problem is highlighted when you use the source code highlighting feature (BTW: very cool feature!!!) and have a class method which returns an external class. Where you can normally click on the return class and jump to it’s documentation in your source code, you are only told the name of the class when it is external to the project.

This is rightfully so, after all “You don’t know what you don’t know.” You can not expect phpDocumentor to know about your external dependencies in a vacuum. What I have come up with in my own experimentation is to stub in a small file in the project called external.php which documents the classes as a 50,000 ft. level, and provides a link to the source of the external library. Obviously, you do not want to include this file in you project, as it would cause class re-definitions and all sorts of problems, but as a stop gap for documentation, it seems to work well.



< ?php
 *    Identify external dependancies for library classes
 *    for purposes of phpDocumentor inclusion
 *            Do not include this file in the project code.
 *            It will cause the application to break. This file
 *            is for documentation only.
 *    @author        Jason E. Sweat
 *    @since        2004-11-20
 *    @version    $Id: external.php,v 1.3 2004/11/22 16:03:35 sweatje Exp $
 *    @package    YourProject
 *    @subpackage    external

 * SimpleTest 
 * @link
class UnitTestCase {}
class WebTestCase {}

 * Web Application Component Toolkit
 * @link
class WACT {}
class FormView {}
class ArrayDataSet extends WACT {}
class DataSpace extends WACT {}
class DatasetDecorator extends WACT {}

 * SPL
 * Standard PHP Library
 * @link
class Exception {}


This "fix" seems to clean up the class tree significantly where you have extended classes from external libraries as well.


PHP5 Setters Should Return $this

Posted 11/15/2004 By Jason

I think that as a convention, I will now have all setters return $this instead of null. I arrived at this decision from messing around with the Specification design pattern (“Domain Driven Design” by Eric Evans, pg. 224). When I was creating a chain of specifications in my Policy object, I ended up making a large number of Factory methods, one for each concrete Specification type. During one refactoring, I added an attribute with a setter for if this was a “normal” specification or just a “warning” specification (one that would log a normal error message if not satisfied, but still allow the policy to take place if other specifications on the chain were sufficient). A little more info on my experiment with the Specification pattern here.

Anyway, you end up with a factory method like this:


    private function fieldEquals($field, $value, $msg, $logdesc) {
        return new FieldEqualsSpecification($field, $value, $this->log, $msg, $logdesc);


And if you want a small variation of this method that sets the warning, you can do:


    private function fieldEqualsWarn($field, $value, $msg, $logdesc) {
        $ret = $this->fieldEquals($field, $value, $msg, $logdesc);
        return $ret;


But, if you have the Specification::setWarning() method return $this instead of null (void) you can eliminate the temporary variable in the second Factory method and end up with this code:


    private function fieldEqualsWarn($field, $value, $msg, $logdesc) {
        return  $this->fieldEquals($field, $value, $msg, $logdesc)->setWarning();


Breaking it down the way the PHP parser does, you get:
$this->fieldEquals() returns an object
which we call the setWarning() method on
which returns an object that we return from this method

I’ll have to contemplate it a bit, but “When in doubt, return $this” may become a mantra for my PHP5 development 😉


Lost Download

Posted 11/11/2004 By Jason

Ages ago (it seems anyway, Feb 2003 timeframe), I wrote a book for Wrox ( PHP Graphics Handbook (Wrox) – ISBN: 1-86100-836-8 ). Wrox published it and then immediately went bankrupt. For a brief period of time they had the source code downloads for the first four chapters available on their web site as When I pointed out that my chapters were missing from the download, they replaced with instead of adding it as an additional file. I somehow failed to ever keep a copy of :(

Over the years, several people have tried to contact me regarding obtaining If anyone managed to download a copy and hold onto it, please email me a copy (jsweat_php AT yahoo DOT com).



Tux Jammies

Posted 10/27/2004 By Jason

This is a picture of my son in his favorite pajamas, the “Tux Jammies”. Ever since he ask which jammies were my favorite, and I answered the Tux jammies, they are now his favorite (sometimes even to the point of demanding that Mommy wash them during the day so that he can wear them twice in a row :) ).
Caleb in Tux jammies

Anyway, a shot of Caleb in his Tux jammies for posterity, before they get too threadbare, or he outgrows them :(


WordPress 1.2.1

Posted 10/12/2004 By Jason

See this announcement regarding the newest version of WordPress. This release patches some recently announced security holes. The upgrade was a reasonably pain free process, just had to hunt for the few tweaks I threw in on the fly.

Update: Don’t forget your plugins. Posts using the syntax highlighter plugin from Scott Yang really look ugly without it 😉


PHP Case Studies Needed

Posted 10/12/2004 By Jason

Marco is looking for PHP success stories to be used for the creation of a web site dedicated to promoting PHP as an “Enterprise Ready” solution. I think this is a very worthy cause. The fact is the numerous “Enterprise” class operation are using PHP and other open source projects, often without management in these operations even knowing (or caring :( ). Any project that seeks to stengthen the awareness of PHP strengthen gets thumbs up 😎 in my book.

So… go read his post, and send ’em in if you got ’em. 😉


How many lines?

Posted 10/8/2004 By Jason

I read Size of phpDocumentor on Joshua Eichorn’s blog and questioned the methodology of simply passing all the *.php and *.inc files through wc -l to count the lines. It does not seem reasonable to me to count whitespace and comments as lines of code.

I though perhaps I could use the whitespace/comment stripping ablity of the php cli binary (the php -w option) in the middle of a shell command to get a more accurate count. Something like:

find . -type f | grep -e 'php$\|inc$' | xargs -n 1 php -w | wc -l

But is seems that this option is somewhat more aggresive with removing new lines that I would have prefered. My next thought was to convert every instance of a ; to ;\n, which you can easily do with sed.

Here was the resulting output from running
find . -type f | grep -e 'php$\|inc$' | xargs -n 1 php -w | sed -e 's/;/;\n/g' | wc -l

This is better, but still leaves you vunerable to ; embeded in stings and counts the <?php and ?> delimiters, etc. Not perfect, but a reasonable shot for a one liner shell command.

A little googling turned up SLOCCount, which professes to count multiple languages and strips comments, etc. It also passes those line count through some interesting statisical manipulation and summarizes the results.

Here is output of sloccount on some of my favorite php projects:
Read the remainder of this entry »


ScriptServer Rocks!

Posted 9/29/2004 By Jason

Well, I finally had a chance to play around with Harry’s ScriptServer.

First of all, if you are unfamiliar with the project, the goal is to hook up client side JavaScript functions with server side PHP scripts. Seamlessly, and without requiring a new HTTP requests.

And ScriptServer is great!!! It took minimal amounts of code to hook up a button of a form to collect several fields from a form, and post them directly to a class method in PHP, and allowing javascript to get a chunk of HTML back from the function for use in replacing the .innerHTML of another division on the page. The results are fantastic, no submit and quick in place edits.

The particular project I was working on that needed this kind of functionality had a large form for the base record that takes some effort to validate and update. Meanwhile, there are several one-to-many relationships that are a part of the model, which is where I am able to put the scriptserver “in place editing” to greatest effect. Essentially I handle the “quick and easy” relationships with this javascript RPC mechanism, and handle the bulk of the base record edits when the main form is submitted.

The only minor issue I encountered was with the new PHP5 case sensitivity of method names.

Anyway, kudos to Harry, works great, check it out. 8)


PHP Development with Oracle

Posted 9/24/2004 By Jason

Here are the slides to the talk “PHP Development with Oracle” I presented at PHP|Works in Toronto on Friday, September 24th, 2004. The presentation is in Microsoft Power Point Slide show format.


Documenting PHP Applications

Posted 9/24/2004 By Jason

Here is the presentation I made on the subject of “Documenting PHP Applications” at PHP|Works in Toronto, on Thursday September 23rd, 2004. It is available in gzip or winzip formats. The presentation itself is in a powerpoint slide show format.