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

PHP Episodio VII: El Despertar de la Fuerza

PHP Episodio VII: El Despertar de la Fuerza

César Suárez Ortega

February 24, 2016
Tweet

More Decks by César Suárez Ortega

Other Decks in Programming

Transcript

  1. View Slide

  2. View Slide

  3. csuarez
    tharandur
    BEET.TECH

    View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. Novedades en PHP 5.x
    PHP 5.3
     Namespaces: use keyword
     Closures
    PHP 5.4
     Traits
     Built-in server

    View Slide

  10. Novedades en PHP 5.x
    PHP 5.5
     Generators
     finally keyword
     PHP 5.6
    Variadic functions: ... Keyword
    phpdbg

    View Slide

  11. View Slide

  12. View Slide

  13. Hiphop
    HPHPc
    Compilador de PHP a C++
     En tiempo de ejecución (JIT compiler)
    HPHPi
    Intérprete para desarrollo
    Descontinuado

    View Slide

  14. Hiphop vs PHP 5
    http://php.webtutor.pl/en/2011/05/17/drupal-hiphop-for-php-vs-apc-benchmark/

    View Slide

  15. View Slide

  16. hhvm
    Máquina virtual
     ¡No es un conversor de código!
    Compilador JIT: PHP a byte code (HHBC)
     HHBC en código máquina x64
    Optimización al vuelo
    Detección de zonas calientes

    View Slide

  17. Hhvm vs hpHpC
    http://hhvm.com/blog/2027/faster-and-cheaper-the-evolution-of-the-hhvm-jit

    View Slide

  18. Hhvm parity
    http://hhvm.com/blog/2813/we-are-the-98-5-and-the-16

    View Slide

  19. Caso real: etSy
    https://codeascraft.com/2015/04/06/experimenting-with-hhvm-at-etsy/

    View Slide

  20. Caso real: etSy
    https://codeascraft.com/2015/04/06/experimenting-with-hhvm-at-etsy/
     La migración no es trivial
    Problemas con las extensiones

    View Slide

  21. Caso real: wikipedia
    https://blog.wikimedia.org/2014/12/29/how-we-made-editing-wikipedia-twice-as-fast/
    Ahorro en infraestructuras
    Ayuda directa de Facebook

    View Slide

  22. View Slide

  23. Hack
    Superconjunto de PHP
     HHVM ejecuta Hack y PHP
    https://learnxinyminutes.com/docs/hack/

    View Slide

  24. Hack

    View Slide

  25. Hack

    View Slide

  26. View Slide

  27. View Slide

  28. performance
    https://kinsta.com/blog/the-definitive-php-7-final-version-hhvm-benchmark/

    View Slide

  29. performance
    https://kinsta.com/blog/the-definitive-php-7-final-version-hhvm-benchmark/

    View Slide

  30. performance
    https://kinsta.com/blog/the-definitive-php-7-final-version-hhvm-benchmark/

    View Slide

  31. performance
    https://kinsta.com/blog/the-definitive-php-7-final-version-hhvm-benchmark/

    View Slide

  32. Scalar Type Hints
    declare(strict_types=1);
    class ElePHPant {
    public $name, $age, $cuteness, $evil;
    public function __construct(string $name, int $age,
    float $cuteness, bool $evil) {
    $this->name = $name;
    $this->age = $age;
    $this->cuteness = $cuteness;
    $this->evil = $evil;
    }
    }

    View Slide

  33. ReturN Type Hints
    function foo(): array {
    return [];
    }
    function foo2(): DateTime {
    return null; // invalid
    }
    function &array_sort(array &$data): array {
    return $data;
    }

    View Slide

  34. Spaceship operatoR
    // Si $a < $b devuelve -1
    // Si $a = $b devuelve 0
    // Si $a > $b devuelve 1
    function compare(int $a, int $b): int
    {
    return $a <=> $b;
    }
    unicode codePoint
    echo "\u{9999}"; //prints 香

    View Slide

  35. Null coalesce operator
    $var = $value1 ?? $value2 ?? $value3;
    Bind closure on Call
    $three = new Value(3);
    $four = new Value(4);
    $closure = function ($delta) {
    var_dump($this->getValue() + $delta);
    };
    $closure->call($three, 4); // prints 7
    $closure->call($four, 4); // prints 8

    View Slide

  36. Group use declarations
    use Doctrine\Common\Collections\Expr\Comparison;
    use Doctrine\Common\Collections\Expr\Value;
    use Doctrine\Common\Collections\Expr\CompositeExpression;
    use Doctrine\Common\Collections\Expr\{ Comparison, Value,
    CompositeExpression };
    Anonymous classes
    $util->setLogger(new class {
    public function log($msg)
    {
    echo $msg;
    }
    });

    View Slide

  37. Engine exceptions
    BaseException (abstract)
    ├── Exception extends BaseException
    ├── ErrorException extends Exception
    └── RuntimeException extends Exception
    └── EngineException extends BaseException
    ├── TypeException extends EngineException
    ├── ParseException extends EngineException
    └── AssertionError extends EngineException

    View Slide

  38. gracias

    View Slide