Slide 1

Slide 1 text

PHP 5.4

Slide 2

Slide 2 text

Federico Lozada Mosto [email protected] @mostofreddy http://www.mostofreddy.com.ar

Slide 3

Slide 3 text

PHP 5.4 Rocks!

Slide 4

Slide 4 text

40 % más rápido

Slide 5

Slide 5 text

empty_loop 0.320 func() 0.748 0.428 undef_func() 0.760 0.440 int_func() 0.703 0.384 $x = self::$x 0.685 0.366 self::$x = 0 0.764 0.445 isset(self::$x) 0.639 0.319 empty(self::$x) 0.690 0.370 $x = Foo::$x 0.987 0.667 Foo::$x = 0 1.084 0.765 isset(Foo::$x) 0.928 0.608 empty(Foo::$x) 0.970 0.651 self::f() 1.085 0.765 Foo::f() 1.210 0.890 $x = $this->x 0.752 0.433 $this->x = 0 0.722 0.402 $this->x += 2 0.632 0.312 ++$this->x 0.587 0.267 --$this->x 0.640 0.320 $this->x++ 0.633 0.314 $this->x-- 0.631 0.311 isset($this->x) 0.684 0.365 empty($this->x) 0.662 0.342 $this->f() 0.937 0.617 $x = Foo::TEST 0.555 0.235 new Foo() 2.393 2.074 $x = TEST 0.596 0.276 $x = $_GET 0.546 0.226 $x = $GLOBALS['v'] 0.856 0.536 $x = $hash['v'] 0.592 0.272 $x = $str[0] 0.839 0.520 ------------------------ PHP 5.3: 24.830'' empty_loop 0.196 func() 0.654 0.458 undef_func() 0.599 0.403 int_func() 0.682 0.486 $x = self::$x 0.408 0.212 self::$x = 0 0.487 0.291 isset(self::$x) 0.484 0.288 empty(self::$x) 0.379 0.184 $x = Foo::$x 0.371 0.176 Foo::$x = 0 0.351 0.155 isset(Foo::$x) 0.322 0.126 empty(Foo::$x) 0.346 0.150 self::f() 0.622 0.426 Foo::f() 0.597 0.401 $x = $this->x 0.394 0.198 $this->x = 0 0.528 0.332 $this->x += 2 0.393 0.197 ++$this->x 0.356 0.161 --$this->x 0.357 0.161 $this->x++ 0.381 0.185 $this->x-- 0.396 0.200 isset($this->x) 0.418 0.222 empty($this->x) 0.426 0.230 $this->f() 0.733 0.537 $x = Foo::TEST 0.395 0.199 new Foo() 1.360 1.164 $x = TEST 0.284 0.089 $x = $_GET 0.404 0.208 $x = $GLOBALS['v'] 0.576 0.380 $x = $hash['v'] 0.440 0.244 $x = $str[0] 0.606 0.410 ------------------------ PHP 5.4: 14.946'' empty_loop 0.369 func() 1.318 0.948 undef_func() 1.635 1.265 int_func() 1.068 0.698 $x = self::$x 0.878 0.509 self::$x = 0 0.818 0.448 isset(self::$x) 0.843 0.474 empty(self::$x) 0.879 0.509 $x = Foo::$x 1.107 0.737 Foo::$x = 0 1.054 0.685 isset(Foo::$x) 1.041 0.672 empty(Foo::$x) 1.051 0.682 self::f() 1.412 1.043 Foo::f() 1.725 1.355 $x = $this->x 0.849 0.479 $this->x = 0 0.976 0.607 $this->x += 2 0.824 0.455 ++$this->x 0.704 0.335 --$this->x 0.722 0.352 $this->x++ 0.737 0.367 $this->x-- 0.736 0.366 isset($this->x) 0.814 0.445 empty($this->x) 0.816 0.446 $this->f() 1.418 1.048 $x = Foo::TEST 0.381 0.011 new Foo() 2.692 2.323 $x = TEST 0.674 0.305 $x = $_GET 0.718 0.349 $x = $GLOBALS['v'] 1.018 0.648 $x = $hash['v'] 0.788 0.418 $x = $str[0] 1.291 0.922 ------------------------ PHP 5.2.9: 31.355''

Slide 6

Slide 6 text

Funciones Palabras recervadas Features

Slide 7

Slide 7 text

● hex2bin() ● http_response_codes() ● get_declared_traits() ● getimagesizefromstring() ● trait_exists() ● header_register_callback() ● class_uses() ● session_status() ● session_register_shutdown() ● mysqli_error_list() ● mysqli_stmt_error_list() ● etc... ● trait ● callable ● insteadof

Slide 8

Slide 8 text

Formato para números binarios

Slide 9

Slide 9 text

Interfaz JsonSerializable

Slide 10

Slide 10 text

data = array( 'Federico', 'Lozada', 'Mosto' ); } public function jsonSerialize() {return $this->data;} } echo json_encode(new Freddy()); //return ["Federico","Lozada","Mosto"] //PHP < 5.4 //{"data":["Federico","Lozada","Mosto"]}

Slide 11

Slide 11 text

Sesiones - session_status - session_handler

Slide 12

Slide 12 text

Session Status

Slide 13

Slide 13 text

Interfaz de Handler de Sessiones Nativa

Slide 14

Slide 14 text

Interfaz de Handler de Sessiones Nativa

Slide 15

Slide 15 text

High Precision Timer

Slide 16

Slide 16 text

= 5.4 sleep(2); $start = $_SERVER['REQUEST_TIME_FLOAT']; echo "time: ".(microtime(1) - $start); //return time: 2.0010209083557

Slide 17

Slide 17 text

Clases & Closures & Arrays

Slide 18

Slide 18 text

Acceso a metodos en la instanciación foo(); //return foo

Slide 19

Slide 19 text

Callable Type Hint

Slide 20

Slide 20 text

Closures & $this name;}; return $callback; } } $o = new Test; $func = $o->getName(); echo $func(); //return Mostofreddy

Slide 21

Slide 21 text

Closure::bindTo val = $val;} function getClosure() { return function() { return $this->val; }; } } $ob1 = new A(1); $ob2 = new A(2); $func = $ob1->getClosure(); echo $func(); //return 1 $func = $func->bindTo($ob2); echo $func(); //return 2

Slide 22

Slide 22 text

Class::{expr}() syntax

Slide 23

Slide 23 text

Sintaxis de array compactos int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) }

Slide 24

Slide 24 text

Array por referencia (Array Deferencing) array( 'nombre'=>'Federico' ) ); } echo getName()['usuario']['nombre']; //return Federico echo PHP_EOL;

Slide 25

Slide 25 text

Built-in web server

Slide 26

Slide 26 text

~/www$ php -S localhost:8080 PHP 5.4.0 Development Server started at Mon Apr 2 11:37:48 2012 Listening on localhost:8080 Document root is /var/www Press Ctrl-C to quit. TIP: para usarlo desde una virtual hay que poner 0.0.0.0

Slide 27

Slide 27 text

~/www$ vim server.sh #! /bin/bash DOCROOT="/var/www" HOST=0.0.0.0 PORT=80 ROUTER="/var/www/router.php" PHP=$(which php) if [ $? != 0 ] ; then echo "Unable to find PHP" exit 1 fi $PHP -S $HOST:$PORT -t $DOCROOT $ROUTER

Slide 28

Slide 28 text

TRAITS

Slide 29

Slide 29 text

Ejemplo simple addLog('foo'); } } $obj = new Test; $obj->foo(); //return LOG: foo

Slide 30

Slide 30 text

Multiple Traits addLog($this->holaMundo()); } } $obj = new Test; $obj->foo(); //return LOG: Hola Mundo!

Slide 31

Slide 31 text

Traits: Composicion put('LOG: '.$m);} } class Test { use Log; public function foo() { $this->addLog('test');} } $obj = new Test; $obj->foo(); //return LOG: test

Slide 32

Slide 32 text

Traits: Herencia foo()." - ".parent::foo(); } } class Base { public function foo() {return 'base';} } class Test extends Base { use Hello; public function foo() {return 'Test';} } $o = new Test; echo $o->foo(); //return Test echo $o->foo_1(); //return Test - base

Slide 33

Slide 33 text

Traits: Resolviendo conflictos play();

Slide 34

Slide 34 text

Traits: Resolviendo conflictos play(); PHP Fatal error: Trait method play has not been applied, because there are collisions with other trait methods on Player in /var/www/test/test_traits.php on line 10 PHP no resuelve el conflicto automáticamente

Slide 35

Slide 35 text

Traits: Resolviendo conflictos - insteadof trait Game { public function play() {return "Play Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music { Music::play insteadof Game; } } $o = new Player; echo $o->play(); //return Play Music

Slide 36

Slide 36 text

Traits: Resolviendo conflictos - rename play(); //return Play Music echo $o->gamePlay(); //return Play Game

Slide 37

Slide 37 text

Traits: Atributos nombre;} } class Empleado { use Usuario; public function setName($nombre) { $this->nombre = $nombre; } } $o = new Empleado; $o->setName('Federico'); echo $o->getName(); //return Federico

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

● Safe mode and all related options ● magic_quotes_gpc ● magic_quotes_runtime ● magic_quotes_sybase ● register_globals ● register_long_arrays ● define_syslog_variables ● y2k_compliance ini options

Slide 40

Slide 40 text

● session_is_registered() ● session_register() ● session_unregister() ● define_syslog_variables() ● get_magic_quotes_gpc && get_magic_quotes_runtime siempre devuelven false ● import_request_variables() ● mysqli_bind_param() ● mysqli_bind_result() ● mysqli_fetch() ● Sqlite (no afecta a sqlite3) Functions & Extensiones

Slide 41

Slide 41 text

Para los temerosos... Tutorial para instalar de manera fácil varias versiones de PHP en un mismo servidor: http://bit.ly/HWJ5lW

Slide 42

Slide 42 text

¿Preguntas?