Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modern PHP

Modern PHP

Overview of tools and language concepts

Thomas Weinert

October 29, 2014
Tweet

More Decks by Thomas Weinert

Other Decks in Programming

Transcript

  1. COMPOSER { "name": "carica/chip", "type": "library", "license": "MIT", "require": {

    "php": ">=5.4", "carica/firmata": "dev-master" }, "require-dev": { "phake/phake": "1.*" }, "autoload": { "psr-4": { "Carica\\Chip\\": "src\\" } } }
  2. ZEPHYR http://zephir-lang.com namespace MyLibrary; class Filter { public function alpha(string

    str) { char ch; string filtered = ""; for ch in str { if (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') { let filtered .= ch; } } return filtered; } }
  3. ANONYMOUS FUNCTIONS $board ->activate() ->done( function () use ($board, $loop)

    { $pin = $board->pins[13]; $pin->mode = Firmata\Board::PIN_MODE_OUTPUT; $loop->setInterval( function () use ($pin) { $pin->digital = !$pin->digital; }, 1000 ); } );
  4. CALLABLE $_ = FluentDOM::create(); $_->formatOutput = true; echo $_( 'ul',

    ['class' => 'navigation'], $_('li', $_->cdata('FluentDOM')) );
  5. TRAITS namespace Carica\Io\Event\Loop { use Carica\Io\Event; trait Aggregation { private

    $_eventLoop = NULL; public function loop(Event\Loop $loop = NULL) { if (NULL !== $loop) { $this->_eventLoop = $loop; } elseif (NULL === $this->_eventLoop) { $this->_eventLoop = Factory::get(); } return $this->_eventLoop; } } }
  6. GENERATORS function xrange($start, $limit, $step = 1) { for ($i

    = $start; $i <= $limit; $i += $step) { yield $i; } }
  7. VARIADICS function f($req, $opt = null, ...$params) { printf( '$req:

    %d; $opt: %d; number of params: %d'."\n", $req, $opt, count($params) ); } f(1); f(1, 2); f(1, 2, 3);
  8. ARGUMENT UNPACKING function add($a, $b, $c) { return $a +

    $b + $c; } $operators = [2, 3]; echo add(1, ...$operators);