Extending PHP 5.3 Closures with Serialization and Reflection

PHP 5.3 has brought with it some powerful and much-needed features like late static bindings, namespaces, and closures (also referred to as anonymous functions and lambda functions). Anyone who is experienced with JavaScript or who has worked with programming languages like Scheme or Lisp should realize the value that anonymous functions can bring to PHP. The PHP Manual explains closures like this:

Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses. Closures can also be used as the values of variables; PHP automatically converts such expressions into instances of the Closure internal class.

PHP has very few predefined classes that are part of the core language, so naturally I was intrigued by the Closure class. The PHP Manual has this to say about the class:

The predefined final class Closure was introduced in PHP 5.3.0. It is used for internal implementation of anonymous functions. The class has a constructor forbidding the manual creation of the object (issues E_RECOVERABLE_ERROR) and the __invoke() method with the calling magic.

The invoke magic method is also a new feature in PHP 5.3. It is called when an object is used in the context of a function (e.g. $object($parameter);). Since Closure objects will be used like functions, this is a critical feature of the Closure object. The Closure class may be perfectly equipped to act like an anonymous function, but it does not provide any extra utility beyond that. A var_dump() of a closure will reveal the functions parameters, but there is no way to get any other information about the Closure (like the actual code of the function). Trying to serialize the Closure throws an Exception and json_encode() just returns an empty JSON string. To make matters worse, the Closure class is final, so there is no way to extend it.

That simply wasn’t going to cut it for me. I wanted to make my own Closure class that was at least able to do the following: Read More »

Popularity: 31% [?]

Posted in: Articles, Development

8 Great Free Icon Packs for Web Developers

It’s surprising how effective a couple of great icons can be. They add polish to an application and really ties the room together, so to speak. And while some applications really need a consistent look-and-feel and thus, custom icons for every single course of action, a lot of the time, there’s no sense in reinventing the wheel. Especially when there are royalty-free, attractive icons available in convenient, aesthetically-homogenous packs. Mmm, icon packs.

So we present to you a round up of a few free icon packs that you can use in your web pages and applications.

And if you haven’t already, make sure you take a look at Smashing Magazine‘s comprehensive, enormous icons post from earlier this month: 55 Free High Quality Icon Sets

Enjoy, but make sure you note the licensing attached to these sets; some are Creative Commons-Attribution or No-Commercial.

Silk Icons” and “Flag Icons” by Famfamfam
Mini Pixel Icons by N.Design
“”Twotiny” by Paul Jarvis
Crystal Clear” by Everaldo Coelho
bwpx.icns” by Paul Armstrong
Bitcons” and “Sanscons” by Some Random Dude
Web Application Icons Set” by WebAppers
Fugue” and “Diagona” by Yasuke Kamiyamane

Other Icon Websites

Note: Not all icons on the following sites are royalty-free!

Popularity: 15% [?]

Posted in: Cool Stuff, Design

A Simple mod_rewrite Tutorial: SEO-Friendly, Attractive URLs

As an intern here at Synapse Studios, I used to be naive about some things. [*Some* things? *Used* to be?—Ed] I’d visit websites, look at their URLs and wonder about the time and planning they must have taken in creating so many directories. Take this news article from Yahoo for example: http://news.yahoo.com/s/ap/20080715/ap_on_bi_ge/oil_prices

Does news.yahoo.com really have the directory structure reflected by this URL? Of course not. That would create an astronomical amount of directories in a website with thousands of index.html files. (And wouldn’t make any sense to begin with; that’s what query strings and dynamic pages are for.) But there’s a way to create legible, sensical URLs that mirror a directory structure but really include variables to a dynamic page. It’s called a rewrite engine. Through the use of a rewrite engine, we can create URLs that make sense to people AND that are attractive to search engines. Take a look at how, after the jump.

Read More »

Popularity: 100% [?]

Posted in: How To

Adventures of a Summer Intern: Volumes II-VII

As I make my second post in this series, we find ourselves deep into the hot, Arizona summer. The weekly posts suggested by Bob faded quickly into bi-monthly posts. So let’s get caught up, shall we?

Over the past month there has been a lot of action around here. We’re closing up several smaller projects and getting a move on a few new, larger-scaled ones. I’ve been able to contribute to six different websites doing various design and development tasks. I’ve created WordPress and Magento templates, worked on WordPress and Magento administration and installation tasks, written custom PHP for a few websites and worked a lot with CSS and simple designs.

Read More »

Popularity: 6% [?]

Posted in: People, Rants

HTML 5: New features, tags, attributes and what else to expect (in about a decade)

HTML 5 is coming our way. So goes the theory, anyway. (Recent chatter puts widespread adoption by user agents at close to a decade out from now… or more.) It is still a moment that many of us are eagerly anticipating. I remember drooling over my keyboard while reading through the HTML 5 Specifications the first time. We have been stuck with HTML 4.01/XHTML 1.0 for a long time and it is time to see some changes.

(In fact, HTML 4.01 has presented us with the longest gap in HTML revisions—it’s been 10 years since it was released; HTML 3.2 only lasted about a year, from 1997 to 1998.) There are some great things we have to look forward to that will make life a lot easier for us developers and designers. We’ll take a look at a few of them after the jump.

Read More »

Popularity: 13% [?]

Posted in: Design, Development, Tech News

Create Favicons for your Website with Free Utilities for Fun and Profit

Favicons Favicons started as a helpful icon identifier for websites back when you’d peruse your bookmarks and track down your favorites. Nowadays, they serve a much more useful purpose: they help brand your site both in browser tabs and in the address bar. Further, if you make use of Firefox’s Bookmarks Toolbar folder like I do, (called the “Links” folder on IE; it usually appears beneath the address bar) you can reduce each of the bookmarks to display just the favicon, allowing you to cram a bunch up there.

Favicon is short for “favorites icon”. A favicon is essentially a resource file in the Windows icon (.ico) format that is associated with a website. Even though the ICO filetype is Windows-based, Linux and Mac systems can still edit and serve them. Favicons are displayed by your browser as a 16×16 pixel image, but should be rendered as a 32×32 image that is then scaled down, as ICOs are scalable to 32×32 in some cases.

[It should be noted that 16x16 is an incredibly small canvas to work with. Chances are, you're going to need to abandon whatever supercool idea you have for a favicon—you're not going to be able to have a mythical dragon slaying a knight guided by a fairie. You might be able to get the dragon's eye. I'm just sayin'.—Ed]

The Windows icon format allows you to embed multiple files into one, so your favicon file should contain both sizes. Fortunately, there are great tools available to create these favicons, and they don’t cost a thing. Take a look at exactly how to make your favicon and links to the necessary tools after the jump.

Read More »

Popularity: 9% [?]

Posted in: Design, How To

Free Software and Open Source Alternatives to Save You Money

The development for open source software is strong and growing. Open source software is software in which the source code is publicly available for examination or contribution. If you talk to a typical person or business, you’ll usually find that their computers are all running Windows and have Microsoft Office installed. Some may even have more expensive software installed like the Adobe Creative Suite applications. By buying and using such high-priced software, it is easy to shell out two or three times as much money on software than on the computer itself. With many capable alternatives, there is a lot of money to be saved by utilizing free and open source software.

Read More »

Popularity: 5% [?]

Posted in: Cool Stuff, How To

Using CSS Sprites to Create Easy Image Rollovers: A Tutorial

In this tutorial, I’ll show you how to quickly and easily use single images and a bit of crafty CSS to create easy image rollovers. You can also use this technique to simplify browser caching of your images by storing multiple images in a single “meta image”, so to speak. (There are some reasons not to do this, though.)

I don’t know if the creators of CSS were thinking of sprites (more on that later) when they thought of the background-position property [Never doubt the range of "what if" thoughts of those who created CSS—Ed] but thanks to many innovative CSS users, we have an excellent way to reduce the load times of our pages. Check it out, after the break.

Read More »

Popularity: 70% [?]

Posted in: Design, How To

Adventures of a Summer Intern: Volume I

Bob asked me to make weekly blog posts outlining what I learn as an intern here at at Synapse Studios, therefore, I will commence my weekly installments. Hopefully these posts will be slightly interesting to those who wish to read and the cliché title is not too much of a deterrent.

Some of the main reasons I wanted to work here was to learn more about enterprise level web development and to learn how to work in a team. The first week has been very educational. I have been exposed to a myriad of new software and ideas. As an intern I am stowed away in the corner of the office and given slightly more mundane tasks than the rest of the group, but even these assignments have proven to be valuable to me.

Read More »

Popularity: 3% [?]

Posted in: Cool Stuff, Development

Magento: A New Open Source Shopping Cart Solution

A good amount of shopping these days is done online, but any developer knows that creating eCommerce websites is not a simple or mundane task. To cook up your own solution can take months of designing, coding, testing and headaches and there is no guarantee that you, your client, or your client’s customers will really benefit from your labors. [Reinventing the wheel is a bad habit we broke ourselves of a couple of years ago when we realized smart open source solutions could be built upon and expanded with great success.—Ed]

At the heart of these eCommerce websites naturally lies the shopping cart. There have been many attempts by both commercial and open source developers to create solutions that can be ported from one project to another. There are literally hundreds of shopping carts available for developers to incorporate into their applications and websites. Instead of talking about several of them and discussing their glories and pitfalls, allow me to present one of the newest shopping cart applications which we think has a great deal of potential.

Read More »

Popularity: 6% [?]

Posted in: Cool Stuff, Development, Tech News