PHEW to PHP !

February 1st, 2008

I did all web-dev in PHP last years. Because PHP deployment is “there”. It proved itself as a practical solution from the smallest shared hosting websites to the huge ones like Flickr.

But PHP as a language is not such pearl and built-in API is very inconsistent. I keep checking out a lot of non-typical PLs and see a lot of good concepts. I would like to find a real web-project to use them on, and make a step forward in my PL experience but I have a tons of PHP code to write right here.

I got depressed about this yesterday, and then I started doing something that I will probably find is a waste of time, but anyway… I started hacking a PHP script that “compiles” some made up language to PHP. I named it PHEW and it even somewhat works… Basically it’s a PHP-ish “language” with modifications where things itched me when working with it..

source PHEW code:

class Users extends Base

	fun getFullName(u)
		return u\:name . " " . u\:surname;

	fun show_hi()
		var usr = #getUserById(@@:auth.getUserId());
		return "Hi {{#getFullName(usr)}}!";

	fun getUserById(id)
		return DBs::selectRow(@@:dbc, [
			:from = @@:t\:users,
			:where = "id = {id} " ,
		]);

generated PHP code:

classUsers  extends Base {

	function getFullName($u){
		return $u['name'] . " " . $u['surname'];

		}
	function show_hi(){
		$usr = Users::getUserById($_GLOBALS['auth'].getUserId());
		return "Hi " . (Users::getFullName($usr)) . "!";

		}
	function getUserById($id){
		return DBs::selectRow($_GLOBALS['dbc'],  array(
			'from' => $_GLOBALS['t']['users'],
			'where' => "id = {$id} " ,
		));

Click to see sample, generated code and a list of changes

Well it’s all in flux, I will keep playing with it probably and see if anything useful comes out.

Leave a Reply