Posts with tag: PHP

28 Feb

Installing xhprof on XAMPP for OSX Lion

Directions adapted from Ben Buckman. Download xhprof. cd path/to/xhprof/…/extension # If you don’t have autoconf… I didn’t. sudo chmod o+w /usr/local/bin #(brew needs to write a symlink there) brew install autoconf sudo /Applications/XAMPP/xamppfiles/bin/phpize Make sure you have a CLI C compiler. I installed one via XCode. sudo MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ LDFLAGS=’-O3

[...read the post]
27 Aug 2012

Decouple User and App State From the Session

When building software components, you want them to be usable in any situation, and especially inside other web apps. The user of your component should be able to inject the user ID and other app state without side effects, and similarly be able to pull that state out after use. That’s why, beyond all the standard

[...read the post]
23 Jul 2012

In Support of Bloated, Heavyweight IDEs

I’ve done plenty of programming in bare-bones text editors of all kinds over the years. Free/open editors were once pretty bad and a lot of capable commercial ones have been expensive. Today it’s still handy to pop a change into Github’s web editor or nano. Frankly, though, I’m unconvinced by arguments suggesting I use text editors

[...read the post]
16 Apr 2012

Define namespace constants using expressions

Since const is parsed at compile-time, you can’t use expressions in namespace constants, but you can use define as long as the name argument is the full name from the global scope (run this): namespace Foo\Bar; const CONST1 = 1; define(‘CONST2′, 1 + 1); // global define(__NAMESPACE__ . ‘\\CONST3′, 1 + 1 + 1); //

[...read the post]
15 Apr 2012

PHP RFC Preview: Dynamic Callback Expressions

I’m posting this to get some initial feedback on this idea before I officially submit an RFC. Background Even with PHP’s growing object-oriented and functional programming features, the callback remains widely-used and useful. However, forcing authors to create callbacks via strings and arrays presents difficulties: Most IDEs do not recognize callbacks as such, and so

[...read the post]
25 Dec 2011

ElggCollection Proposal

An ElggCollection entity would store an ordered set of integers optimized for filtering and/or ordering SQL queries of entities, annotations, or other tables with integer primary keys.

[...read the post]
28 Sep 2011

String Subtypes for Safer Web Programming

Valid HTML markup involves several different contexts and escaping rules, yet many APIs give no precise indication of which context their string return values are escaped for, or how strings should be escaped before being passed in (let’s not even get into character encoding). Most programming languages only have a single String type, so there’s

[...read the post]
15 Sep 2011

RotURL: Rot13 for URLs

RotURL is a simple substitution cipher for encoding/obscuring URLs embedded in other URLs (e.g. in a querystring). Also, common chars that need to be escaped (:/?=&%#) are mapped to infrequently used capital letters, so this generally yields shorter querystrings, too. /**  * Rot35 with URL/urlencode-friendly mappings. To avoid increasing size during * urlencode(), commonly encoded

[...read the post]
18 Aug 2011

NetBeans Love & Hate

For those cases where you have to work on remote code, NetBeans‘ remote project functionality seems to put it ahead of other PHP IDEs. It pulls down a tree of files and uploads files that you save. Having a local copy allows it to offer its full code comprehension, auto-complete, and great rename refactoring for “remote”

[...read the post]
18 Jul 2011

Helping Netbeans/PhpStorm with Autocomplete/Code-hinting

Where Netbeans can’t guess the type/existence of a local variable, you can tell it in a multiline comment: /* @var $varName TypeName */ After this comment (and as long as TypeName is defined in your project/project’s include path), when you start to type $varName, Netbeans will offer to autocomplete it, and will offer TypeName method/property suggestions.

[...read the post]
22 Apr 2011

Xdebug 2.1.1 for XAMPP OSX 1.7.3

xdebug-211-xampp-osx.tgz contains a freshly compiled xdebug 2.1.1 module for XAMPP OSX, using this tutorial as a guide. The archive contains step-by-step install instructions w/ bash commands. Happy debugging with fewer bugs.

[...read the post]
16 Apr 2011

Shibalike: a PHP emulation of a Shibboleth environment

Update 2011-06-23: All the essential components of Shibalike are complete and the project is hosted on Github. This is currently blueprint-ware, but I’m excited about it. A co-worker and I have laid out a design for a flexible system that can emulate a working Apache/PHP Shibboleth stack, without requiring any outside resources (e.g. an IdP,

[...read the post]
2 Feb 2011

Filtering WordPress Navigation Menus

WordPress 3 introduced native navigation menus, usually created via the wp_nav_menu theme function and the built-in Custom Menu widget.  If you have a menu with a deep hierarchy, you may want to display only the active branch and the submenu directly below the active item (given class “current-menu-item” by WordPress). You can see this menu

[...read the post]
25 Jan 2011

Simpler API for Zend’s built-in Firebug Logger

Zend Framework has functionality to send messages to the Firebug console (via Firefox’s FirePHP addon), but if you’re not using the ZF front controller, the API is a bit of a pain. Besides your instance of Zend_Log, you must keep track of a few additional objects just to manually flush the headers after all your

[...read the post]
21 Nov 2010

Customizing a Zend Navigation Menu

Zend Navigation has a menu helper class that can output a basic nested UL menu. You can set id/class attributes on the A elements, and it adds an “active” classname to A elements in the active branch, but customizing the markup beyond that gets complicated.

[...read the post]
1 Nov 2010

A Zend Framework App in a Single File

Most PHP micro-frameworks I’ve reviewed have some major cons: incomplete namespacing of functions/classes/global vars; doing too much/little; being under-tested; and the worst: forcing a unique (and usually under-documented) code structure that will make it difficult to “graduate” an app into a more full-featured framework. It also seems silly to rely on “micro-optimized” code if performance

[...read the post]
1 Nov 2010

Minify update

Minify 2.1.4 is approaching release and will have several long-awaited features and hopefully easier configuration. Looking towards version 2.2/3(?), I recently committed the beginnings of a complete refactoring of the Minify API. The goal is to have a more flexible and extensible design that can include plugins like LESS and maybe handle @imports on the

[...read the post]
17 Oct 2010

Elgg Core Proposal: New Table “entity_list_items”

[This proposal has been superseded with ElggCollection.] As of Elgg 1.7.4 there’s no way to specify a specific list or ordering of entities for use in an elgg_get_entities query. E.g. one might want to implement: A “featured items” list for a group or user widget. On a group page this could be implemented in “left”

[...read the post]
6 Aug 2010

PHP UTF-8 string class

A couple years ago I put together a class for UTF-8 strings, kind of a smart wrapper around Harry Fuecks’s phputf8 string functions. All Utf8String objects—if I’m not missing bugs!—are guaranteed to house valid UTF-8 strings. The factory, make(), enforces UTF-8 validity, stripping non-UTF-8 bytes (default) or replacing them with Utf8String::$replacement (? by default). $str

[...read the post]
14 Jul 2010

MVC: M != the Database

Great article on the misunderstood scope of the “Model” in the Model-View-Controller architecture. The takehome: Models are commonly thought of as wrappers for database access/stored objects, but application state and business logic need to go in them, too. Otherwise you get bloated controller and/or views that clumsily try to take care of these concerns. Earlier

[...read the post]