Home > php教程 > php手册 > 131个字符的php framework

131个字符的php framework

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 08:52:23
Original
1320 people have browsed it

  在friendfeed上看到这个链接 —— The 140 Characters Webapp Challenge!,这个比赛要求用140个字符的代码造就一个web应用。

  里头有36个程序可供投票,基本上全是脚本语言大杂烩:php,perl,ruby,javascript。实现的应用也是五花八门,有相册,类twitter,小游戏,甚至还有php代码框架?摘录如下:

  require __DIR__.'/c.php';

  if (!is_callable($c = @$_GET['c'] ?: function() { echo 'Woah!'; }))

  throw new Exception('Error');

  $c();

  这段代码利用了php5.3的一些新特性:

  __DIR__

  Anonymous functions

  ?:运算符

  代码只有131个字符,由于代码极为简陋,安全性也是没得保障的,只能算一个程序的统一入口罢了。

  如果用php 5.2来写这段代码,大概就是:

  require dirname(__FILE__).'/c.php';

  if (!is_callable($c = @$_GET['c'] ? $_GET['c'] : create_function('', "echo 'Woah!';")))

  throw new Exception('Error');

  $c();

  如果要让这段代码变得实用点,可以在$c前面加上一个前缀,这样安全性会有进一步提升,代码也会相应的增加若干字节。



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template