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. csuarez
    tharandur
    BEET.TECH

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  6. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. 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 full-size slide

  11. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  17. 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 full-size slide

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

    View full-size slide

  19. 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 full-size slide

  20. 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 full-size slide

  21. 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 full-size slide

  22. 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 full-size slide