PHP6 gets a COMEFROM statement

One of the more controversial additions to PHP6 is the GOTO. Some have argued it flys in the face of many years good programming sense but there are valid use cases, when running performance critical operations such as parsing, where the overhead of making PHP user function calls becomes significant.

Anyway GOTO seems to have opened the gates to some more radical language modifications and recent discussion a revolved around adding a COMEFROM statement to PHP, which led to an initial patch being applied to the PHP6 CVS branch here.

Precedent for COMEFROM can be found in INTERCAL, a language which, for various reasons, never hit mainstream but aimed at being a better LISP, as this code listing illustrates.

Like GOTO, COMEFROM could lead to spagetti if used unwisely, so the initial implementation places a sensible restriction on it’s use: you can only COMEFROM a PHP script which is not the script where COMEFROM was used. An example if I have some include file like;


<?php
// login.php - the script we want to COMEFROM
function login($username, $password) {
   $auth = new Auth();
   return $auth->isValidUser($username, $password);
}

I can step into this with COMEFROM like;


<?php
// index.php
require_once 'login.php';

class MyAuth implements LoginHandler {
    // Some other implementation providing the same interface
    function login($username, $password) {
        // authenticate against, say, an LDAP server
    }
}

// Execute a COMEFROM, replacing use of Auth class with MyAuth
COMEFROM 'login.php:3' [
   $auth = new MyAuth();
   return $auth->isValidUser($username, $password);
]

if ( login($_POST['username'], $_POST['password'] )) {
   echo "You are logged in<br />";
}

As the above code illustrates, this gives you the possibility to override the behaviour of code without having to physically alter it or worry about stuff like dynamic includes. What this trivial example doesn’t illustrate is some of the more advanced things COMEFROM enables, such as functional programming, macros and Ruby-like “blocks”, all of which make PHP significantly more dynamic. That said, at the moment, what I see as missing is a way to return back into the code you have COMEFROM, which would allow for stuff like an extremely fast AOP implementation – perhaps GOTO could be extended to support this?

Anyway – could this be the feature that drives demand for hosts to migrate to PHP?

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • ivanv

    I think you meant “open the gates of HELL”… and a flood of oni aliens will come down upon us.

    sigh…

  • Seinfeld

    1st of April :D

  • ivanv

    Oh, it’s still 31 here, LOL

  • http://boyohazard.net Octal

    Nice one Harry :D

  • jayboots

    Wow, I’m impressed at the level of detail you went to for this joke. I was smirking at the very mention of comefrom but laughed outloud at: “INTERCAL, a language which, for various reasons never hit mainstream”.

    Good one!!

  • http://www.phpism.net Maarten Manders

    Finally! ;)

  • http://www.phppatterns.com HarryF

    Note to self: remember what time zone I’m in next time

  • Dr Livingston

    sorry harry, i’m not convinced…

    goto? comefrom? wtf?? what are they doing to our language huh :(

  • Dr Livingston

    damn it… you got me :lol:

  • http://www.phpism.net Maarten Manders

    By the way, i love this INTERCAL code. ;)

  • http://www.michaelkrenz.de mkrz

    Damn, you got me! :) Definitely one of the better April jokes I’ve seen.

  • http://www.litfuel.net jplush76

    dammit, I have to start realizing today is april fools day I totally thought you were serious and I was remember my AS/400 RPG days of the goto and it was a nightmare, whew
    ya got me :)

  • ajking

    Never mind COMEFROM. Having looked at the INTERCAL code, I think it’s time we put the “Please” statement in PHP. Especially for debugging, as in “Please let this work!” :-) ROTFL, Harry, great post.

  • Anonymous

    and I was remember my AS/400 RPG days of the goto

    Except the GOTO part isn’t a joke – haven’t seen exactly how it’s going to work but it looks like it will be a way to jump between labels inside a switch statement .

  • mx2k

    that will be the next php egg,

    
    
    output: harry says hi
    
  • mx2k


    sorry i’m used to the forum tags

  • Gator99

    Great news, when is the Gosub tag coming out, php 6.1?

  • Pingback: PDI^2 :: Archivio dei pesci d’aprile :: April :: 2006

  • http://www.deanclatworthy.com Dean C

    Ah you’re evil Harry – you got me here :(

  • _theworks

    Ok this is confusing? are they really adding GOTO and COMEFROM ? or was this an april fools joke?

  • Ryan Wray

    @_theworks:
    It is was a well-constructured April fools joke. :)

  • http://www.sdynamics.nl Nova

    hehe, nice one

  • spinmaster

    nice one… ;) you got me there!

  • http://www.ezpdo.net nauhygon

    when i first saw the post, i was seriouly missing the ‘caller’ property in the javascript Function object and thinking if COMEFROM was of the same nature. harry, nice one! :)

  • http://www.errewf.it RaS!

    GOTO sucks

  • XoloX

    Thank god

  • Pingback: Team Murder » Ha! No, Wait! Oh. Ha!

  • seodevhead

    I remember in my first computer science class, unbeknownst to all, I wrote an entire program using goto’s and not a single function. Looking back, I was the first one to finish the perfectly working program, but then again was the first to receive an F. I thought I was sooo cool with my newfound statement, the GOTO.

  • Pingback: Hacksaw: teh intarweb si 1337 » PHP 6 is going to suck eggs

  • lsd

    may be