Reason #184 why PHP sucks

class Blah {
        public static function
        hello($id) {
                printf("Static");
        }

        public function
        hello() {
                printf("Instance");
        }
}

Blah::hello(5);
$x = new Blah();
$x->hello();

You knows it...

Update: To Clarify My Intentions

So I was building a very quick ORM class and thought for ease of use it would be a nice to provide both static and instance methods to delete().

For example:

Blah_Model::delete(1234);

$blah = new Blah_Model(1234);
$blah->delete();

I don't see any problem with redeclaring methods as long as they're in different contexts, I don' care for PHP4 compatibility, but unfortunately this isn't how PHP works.

Now .. it can be done using __callstatic with PHP 5.3, this isn't the approach I took. Instead I implemented a check for $this:

class Blah {
	function delete( $id = NULL ) {
		if( isset($this) ) {
			printf("Instance Method\n");
		} 
		else {
			printf("Static Method\n");
		}
	} 
}
Skip to Page:  1 2 … 8

dwm and dmenu

For the past few months I've been using DWM by the good folks over at Suckless.org, I've finally found a window manager where I use perhaps 90% of it's features on a daily basis, yet I'm never left wanting more.

I've been admiring the simplicity in combination with the `dmenu` program, my status bar is a simple `rc` script which prints the time, load and my wifi status on a single line every few seconds. Gone are the days of desktop status widgets taking up the resources better suited for other productive work.

#!/usr/bin/env rc
# start `dwm` like: $HOME/this-script.rc | dwm
while ( true ) { 
  {
    echo -n 'time: '
    uptime | cut -f 2 -d ' ' 

    echo -n 'load: '
    cat /proc/loadavg | cut -f 1 -d ' ' 

    echo -n 'wifi: '
    iwconfig eth1 | grep 'Link Quality' | cut -f 2 -d '=' | cut -f 1 -d ' ' 
  } | column | tr "\t" '  '

  sleep 2
}

The menu being another simple shell script which spits out the contents of my $HOME/.dmenu/ directory, containing all the scripts or symlinks to programs I use on a regular basis, to `dmenu` and executes whichever one I choose.

#!/bin/sh
if [ -d $HOME/.dmenu ]; then
  cmd=`ls -1 $HOME/.dmenu | dmenu $*`
  if [ "x$cmd" != "x" ]; then
    exec "$HOME/.dmenu/$cmd"
  fi  
fi

There are bugs that I've not been able to track down yet which are only apparent with Windows applications running in `wine` like Photoshop®, while the application works flawlessly, whenever I click on tool windows they jump a few pixels to the right. Odd, but still usable.

While it's all up and running it looks something like this.
Skip to Page:  1 2 … 8

MPC Playlist Handler

One tiny problem I found with MPC is that it didn't integrate as nicely with Firefox/Opera as I would wish, for example when I download a .m3u or .pls file I can't have the streams it points to added to the MPC playlist.

So the solution is:

#!/bin/bash
if [ -z "$1" ]; then
  echo "Usage: `basename $0` " > /dev/sdterr
  exit
fi

url=$1
# Presumed to be a remote URL
if [ ! -f "$1" ]; then
  tmpfile=`mktemp`
  wget --quiet -O "$tmpfile" "$1" && url=$tmpfile
fi

if [ ! -f "$url" ]; then
  echo "Error: cannot retrieve playlist" > /dev/stderr
  exit
fi

cat $url | grep -E '^File' | cut -f 2 -d '=' | xargs mpc add 

Takes either a local file or a URL to the playlist as the first parameter and adds all streams/files to the MPC playlist.

Skip to Page:  1 2 … 8

More on pam_chroot and suPHP

I finally got round to solving my per-user chrooting issues by hacking suPHP to read the /etc/security/chroot.conf file if no global chroot is specified, allowing individual users to be chrooted.

The patch is against 0.6.3 with all the Debian patches (or perhaps it's 0.6.2-3) and is running in production at the moment, but I wouldn't really consider it ready for production use elsewhere.

Download: suphp-0.6.3-chroot.diff

Skip to Page:  1 2 … 8

About

Harry is a professional developer and sysadmin from London, UK.

He's an atheist, employed at PixelMags LLC, a socialist and has a pragmatic outlook on life, love and religion.

Bookmarks

I'm constantly finding interesting stuff, here are some of the things I've bookmarked recently:

HarryR on Faves.com