News for hackers. Stuff that matters.

Ask HN: What's the coolest PHP snippet you know?

I'm redecorating the office, and came across the challenge of needing 8 lines of PHP to spraypaint onto the wall at LinkUp.

The problem: I can't think of any code that's cool enough to display in 12" lettering for an extended period of time.

What code would you put up? The heart of phpBB? Leaked source code from the early days of Facebook? The first sample code that Rasmus ever made public? A WTF answer from phpGolf?

( 7 comments | 9 points | on HN )
Re:Ask HN: What's the coolest PHP snippet you know? by cheald on Friday July 29, 2011 @08:52AM (#2821470)
I'd just go with "T_PAAMAYIM_NEKUDOTAYIM", personally.
Re:Ask HN: What's the coolest PHP snippet you know? by nbpoole on Thursday July 28, 2011 @10:41PM (#2819936)
http://www.reddit.com/r/programming/comments/dst56/today_i_l...

One of the code examples from here might be good if you're looking to scare people :-P

Edit: I have a more serious suggestion. Why not pick 8 lines from your own codebase?

Re:Ask HN: What's the coolest PHP snippet you know? by ecaron on Friday July 29, 2011 @12:01AM (#2820111)
I have been playing with that, the problem is that everything is really just cool within its context. We also try to follow the logic that good code must be easy to understand, not the kind of magic code that works great but can't be debugged. Put that code on the wall and it is, well, boring.

The sample I started with is kind of a magic-method interpretation of how our system works:

  <?php
  $jobs = array();
  foreach (Companies::getAll AS $company) {
    array_push($jobs, $company->getJobs();
  }
  $results = Search::fromKeyword($jobs);
  foreach ($results AS $result) {
    $result->displayJob();
  }
Re:Ask HN: What's the coolest PHP snippet you know? by sdrinf on Thursday July 28, 2011 @10:52PM (#2819956)
print_r( json_decode( file_get_contents( "http://twitter.com/statuses/user_timeline/hntweets.json?coun...),true ));

Oneliner: prints out the latest HN frontpage story

Re:Ask HN: What's the coolest PHP snippet you know? by gorog on Friday July 29, 2011 @04:05AM (#2820669)
I would include a pattern matching line:

$date = "2011-07-29";

$list($year, $month, $day) = explode("-", $date);

With whatever is cooler than a date, or with the company's creation date.

Re:Ask HN: What's the coolest PHP snippet you know? by smokeyhobie on Friday July 29, 2011 @01:06AM (#2820299)
while(pcntl_fork()|1);
Re:Ask HN: What's the coolest PHP snippet you know? by ryanto on Saturday July 30, 2011 @02:02AM (#2825030)
exit;