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

PHP 5.2.9: 31.355'' PHP 5.3: 24.830'' PHP 5.4: 14.946''
Funciones
Palabras recervadas
     Features
hex2bin()
trait       http_response_codes()
callable    get_declared_traits()
insteadof   getimagesizefromstring()
            trait_exists()
            header_register_callback()
            class_uses()
            session_status()
            session_register_shutdown()
            mysqli_error_list()
            mysqli_stmt_error_list()
            etc...
Formato para
números binarios

     <?php
     $nroBinario = 0b10;
     echo $nroBinario.PHP_EOL;

     //return 2
Interfaz JsonSerializable
<?php
class Freddy implements JsonSerializable
{
   public $data = [];
   public function __construct() {
     $this->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"]}
Sesiones
- session_status
- session_handler
Session Status


<?php
function status() {
     $status = session_status();
     if($status == PHP_SESSION_DISABLED) {
           echo "Session is Disabled";
     } else if($status == PHP_SESSION_NONE ) {
           echo "Session Enabled but No Session values Created";
     } else {
           echo "Session Enabled and Session values Created";
     }
}

status();
//return Session Enabled but No Session values Created

session_start();
status();
//return Session Enabled and Session values Created
Interfaz de Handler de Sessiones Nativa


       S
 N TE
   <?php
A   $obj = new MySessionHandler;

    session_set_save_handler(
       array($obj, "open"),
       array($obj, "close"),
       array($obj, "read"),
       array($obj, "write"),
       array($obj, "destroy"),
       array($obj, "gc")
    );
Interfaz de Handler de Sessiones Nativa



      R  A
  O MySessionHandler
 H class
   <?php
A        implements SessionHandlerInterface
    {
        public function open($savePath, $sessionName) {}
        public function close() {}
        public function read($id) {}
        public function write($id, $data) {}
        public function destroy($id) {}
        public function gc($maxlifetime) {}
    }
    $handler = new MySessionHandler();
    session_set_save_handler($handler, true);
    session_start();
High Precision Timer
<?php
// PHP < 5.4
$start = microtime(1);
sleep(2);
echo "time: ", (microtime(1) - $start);
//return time: 2.0010209083557


// PHP >= 5.4
sleep(2);
$start = $_SERVER['REQUEST_TIME_FLOAT'];
echo "time: ".(microtime(1) - $start);
//return time: 2.0010209083557
Clases
   &
Closures
   &
 Arrays
Acceso a metodos en la instanciación




<?php
class Test
{
     public function foo(){ return 'foo';}
}

echo (new Test())->foo();

//return foo
Callable Type Hint


<?php
class Test {
      public function foo() {return 'foo';}
      static public function bar() {return 'bar';}
      public function __invoke(){return 'invoke';}
}
function run(callable $func) {
      echo $func();
}
$o = new Test;
$var = 'excepcion';
run(['Test', 'bar']); //return bar
run([$o, 'foo']);      //return foo
run($o);                 //return invoke
run($var);            //Catchable fatal error: Argument
                        //1 passed to run() must be callable
Closures & $this




<?php
class Test {
     protected $name = 'Mostofreddy';
     public function getName() {
          $callback = function() {return $this->name;};
          return $callback;
     }
}
$o = new Test;
$func = $o->getName();
echo $func(); //return Mostofreddy
Closure::bindTo



<?php
class A {
   function __construct($val) {$this->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
Class::{expr}() syntax




<?php
class Test {
     static public function foo(){ return "method foo";}
     static public function bar(){ return "method bar";}
}

$method = true;

echo Test::{($method)?'foo':'bar'}();

//return method foo
Sintaxis de array compactos



                                //return
                                array(6) {
                                  [0]=>
<?php                             int(0)
$array = [0, 1, 2, 3, 4];         [1]=>
var_dump($array);                 int(1)
                                  [2]=>
                                  int(2)
                                  [3]=>
                                  int(3)
                                  [4]=>
                                  int(4)
                                }
Array por referencia (Array Deferencing)



<?php
$txt = "Erase una vez";
echo explode(" ", $txt)[0]; //return Erase
echo PHP_EOL;

function getName() {
  return array(
     'usuario' => array(
        'nombre'=>'Federico'
     )
  );
}

echo getName()['usuario']['nombre']; //return Federico
echo PHP_EOL;
Built-in web server
~/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
~/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
TRAITS
Ejemplo simple


<?php
trait Log {
   public function addLog($m) {echo 'LOG: '.$m;}
}

class Test {
   use Log;
   public function foo() {
     $this->addLog('foo');
   }
}
$obj = new Test;
$obj->foo();

//return LOG: foo
Multiple Traits


<?php
trait Log {
   public function addLog($m) {echo 'LOG: '.$m;}
}
trait Mensaje {
   public function holaMundo() {return "Hola Mundo!";}
}
class Test {
   use Log, Mensaje;
   public function foo() {
         $this->addLog($this->holaMundo());
   }
}
$obj = new Test;
$obj->foo();

//return LOG: Hola Mundo!
Traits: Composicion


<?php
trait File {
   public function put($m) {error_log($m, 3, '/tmp/log');}
}
trait Log {
   use File;
   public function addLog($m) {$this->put('LOG: '.$m);}
}

class Test {
   use Log;
   public function foo() { $this->addLog('test');}
}
$obj = new Test;
$obj->foo();

//return LOG: test
Traits: Herencia

<?php
trait Hello {
   public function foo () {return "traits";}
   public function foo_1() {
        return $this->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
Traits: Resolviendo conflictos



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


    <?php
    trait Game {
       public function play() {return "Play Game";}
    }
    trait Music {
       public function play() {return "Play Music";}
    }
    class Player {
       use Game, Music;
    }
    $o = new Player;             PHP no resuelve el
    echo $o->play();        conflicto automáticamente

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
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
Traits: Resolviendo conflictos - rename


<?php
trait Game {
   public function play() {return "Play Game";}
}
trait Music {
   public function play() {return "Play Music";}
}
class Player {
   use Game, Music {
      Game::play as gamePlay;
      Music::play insteadof Game;
   }
}
$o = new Player;
echo $o->play();           //return Play Music
echo $o->gamePlay(); //return Play Game
Traits: Atributos


<?php
trait Usuario {
   protected $nombre;
   public function getName(){ return $this->nombre;}
}
class Empleado {
   use Usuario;
   public function setName($nombre) {
        $this->nombre = $nombre;
      }
}
$o = new Empleado;
$o->setName('Federico');
echo $o->getName();

//return Federico
ini options

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
Functions & Extensiones
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)
Para los temerosos...
Tutorial para instalar de
manera fácil varias
versiones de PHP
en un mismo servidor:

http://bit.ly/HWJ5lW
¿Preguntas?

More Related Content

What's hot

Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?Nikita Popov
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsPierre MARTIN
 
R57shell
R57shellR57shell
R57shellady36
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and BeyondJochen Rau
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixturesBill Chang
 

What's hot (20)

Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
zinno
zinnozinno
zinno
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
C99
C99C99
C99
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Php
PhpPhp
Php
 
R57shell
R57shellR57shell
R57shell
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 

Viewers also liked

Solucionador de problemas
Solucionador de problemasSolucionador de problemas
Solucionador de problemasAbraham Ender
 
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOSINDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOSAbraham Ender
 
Las investigaciones científicas oscuras y sospechosas son desenfrenadas
Las investigaciones científicas oscuras y sospechosas son desenfrenadasLas investigaciones científicas oscuras y sospechosas son desenfrenadas
Las investigaciones científicas oscuras y sospechosas son desenfrenadasAbraham Ender
 
Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...
Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...
Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...Abraham Ender
 
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOSINDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOSAbraham Ender
 

Viewers also liked (6)

Solucionador de problemas
Solucionador de problemasSolucionador de problemas
Solucionador de problemas
 
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOSINDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
 
Nuevatecnologia
NuevatecnologiaNuevatecnologia
Nuevatecnologia
 
Las investigaciones científicas oscuras y sospechosas son desenfrenadas
Las investigaciones científicas oscuras y sospechosas son desenfrenadasLas investigaciones científicas oscuras y sospechosas son desenfrenadas
Las investigaciones científicas oscuras y sospechosas son desenfrenadas
 
Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...
Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...
Del Homo Sapiens al Homo Depredator o cómo fabricar la sexta extinción masiva...
 
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOSINDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
INDUSTRIA FARMACÉUTICA EXPEDIENTES NO AUTORIZADOS
 

Similar to PHP 5.4

Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128PrinceGuru MS
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?Radek Benkel
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Masahiro Nagano
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsMark Baker
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHPIan Barber
 

Similar to PHP 5.4 (20)

Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 Generators
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHP
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 

More from Federico Damián Lozada Mosto (8)

Php 5.6
Php 5.6Php 5.6
Php 5.6
 
Solid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesSolid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examples
 
Implementando una Arquitectura de Microservicios
Implementando una Arquitectura de MicroserviciosImplementando una Arquitectura de Microservicios
Implementando una Arquitectura de Microservicios
 
Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6
 
Composer
ComposerComposer
Composer
 
Travis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHPTravis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHP
 
Introduction to unit testing
Introduction to unit testingIntroduction to unit testing
Introduction to unit testing
 
Scrum
ScrumScrum
Scrum
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

PHP 5.4

  • 5. empty_loop 0.369 empty_loop 0.320 empty_loop 0.196 func() 1.318 0.948 func() 0.748 0.428 func() 0.654 0.458 undef_func() 1.635 1.265 undef_func() 0.760 0.440 undef_func() 0.599 0.403 int_func() 1.068 0.698 int_func() 0.703 0.384 int_func() 0.682 0.486 $x = self::$x 0.878 0.509 $x = self::$x 0.685 0.366 $x = self::$x 0.408 0.212 self::$x = 0 0.818 0.448 self::$x = 0 0.764 0.445 self::$x = 0 0.487 0.291 isset(self::$x) 0.843 0.474 isset(self::$x) 0.639 0.319 isset(self::$x) 0.484 0.288 empty(self::$x) 0.879 0.509 empty(self::$x) 0.690 0.370 empty(self::$x) 0.379 0.184 $x = Foo::$x 1.107 0.737 $x = Foo::$x 0.987 0.667 $x = Foo::$x 0.371 0.176 Foo::$x = 0 1.054 0.685 Foo::$x = 0 1.084 0.765 Foo::$x = 0 0.351 0.155 isset(Foo::$x) 1.041 0.672 isset(Foo::$x) 0.928 0.608 isset(Foo::$x) 0.322 0.126 empty(Foo::$x) 1.051 0.682 empty(Foo::$x) 0.970 0.651 empty(Foo::$x) 0.346 0.150 self::f() 1.412 1.043 self::f() 1.085 0.765 self::f() 0.622 0.426 Foo::f() 1.725 1.355 Foo::f() 1.210 0.890 Foo::f() 0.597 0.401 $x = $this->x 0.849 0.479 $x = $this->x 0.752 0.433 $x = $this->x 0.394 0.198 $this->x = 0 0.976 0.607 $this->x = 0 0.722 0.402 $this->x = 0 0.528 0.332 $this->x += 2 0.824 0.455 $this->x += 2 0.632 0.312 $this->x += 2 0.393 0.197 ++$this->x 0.704 0.335 ++$this->x 0.587 0.267 ++$this->x 0.356 0.161 --$this->x 0.722 0.352 --$this->x 0.640 0.320 --$this->x 0.357 0.161 $this->x++ 0.737 0.367 $this->x++ 0.633 0.314 $this->x++ 0.381 0.185 $this->x-- 0.736 0.366 $this->x-- 0.631 0.311 $this->x-- 0.396 0.200 isset($this->x) 0.814 0.445 isset($this->x) 0.684 0.365 isset($this->x) 0.418 0.222 empty($this->x) 0.816 0.446 empty($this->x) 0.662 0.342 empty($this->x) 0.426 0.230 $this->f() 1.418 1.048 $this->f() 0.937 0.617 $this->f() 0.733 0.537 $x = Foo::TEST 0.381 0.011 $x = Foo::TEST 0.555 0.235 $x = Foo::TEST 0.395 0.199 new Foo() 2.692 2.323 new Foo() 2.393 2.074 new Foo() 1.360 1.164 $x = TEST 0.674 0.305 $x = TEST 0.596 0.276 $x = TEST 0.284 0.089 $x = $_GET 0.718 0.349 $x = $_GET 0.546 0.226 $x = $_GET 0.404 0.208 $x = $GLOBALS['v'] 1.018 0.648 $x = $GLOBALS['v'] 0.856 0.536 $x = $GLOBALS['v'] 0.576 0.380 $x = $hash['v'] 0.788 0.418 $x = $hash['v'] 0.592 0.272 $x = $hash['v'] 0.440 0.244 $x = $str[0] 1.291 0.922 $x = $str[0] 0.839 0.520 $x = $str[0] 0.606 0.410 ------------------------ ------------------------ ------------------------ PHP 5.2.9: 31.355'' PHP 5.3: 24.830'' PHP 5.4: 14.946''
  • 7. hex2bin() trait http_response_codes() callable get_declared_traits() insteadof getimagesizefromstring() trait_exists() header_register_callback() class_uses() session_status() session_register_shutdown() mysqli_error_list() mysqli_stmt_error_list() etc...
  • 8. Formato para números binarios <?php $nroBinario = 0b10; echo $nroBinario.PHP_EOL; //return 2
  • 10. <?php class Freddy implements JsonSerializable { public $data = []; public function __construct() { $this->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"]}
  • 12. Session Status <?php function status() { $status = session_status(); if($status == PHP_SESSION_DISABLED) { echo "Session is Disabled"; } else if($status == PHP_SESSION_NONE ) { echo "Session Enabled but No Session values Created"; } else { echo "Session Enabled and Session values Created"; } } status(); //return Session Enabled but No Session values Created session_start(); status(); //return Session Enabled and Session values Created
  • 13. Interfaz de Handler de Sessiones Nativa S N TE <?php A $obj = new MySessionHandler; session_set_save_handler( array($obj, "open"), array($obj, "close"), array($obj, "read"), array($obj, "write"), array($obj, "destroy"), array($obj, "gc") );
  • 14. Interfaz de Handler de Sessiones Nativa R A O MySessionHandler H class <?php A implements SessionHandlerInterface { public function open($savePath, $sessionName) {} public function close() {} public function read($id) {} public function write($id, $data) {} public function destroy($id) {} public function gc($maxlifetime) {} } $handler = new MySessionHandler(); session_set_save_handler($handler, true); session_start();
  • 16. <?php // PHP < 5.4 $start = microtime(1); sleep(2); echo "time: ", (microtime(1) - $start); //return time: 2.0010209083557 // PHP >= 5.4 sleep(2); $start = $_SERVER['REQUEST_TIME_FLOAT']; echo "time: ".(microtime(1) - $start); //return time: 2.0010209083557
  • 17. Clases & Closures & Arrays
  • 18. Acceso a metodos en la instanciación <?php class Test { public function foo(){ return 'foo';} } echo (new Test())->foo(); //return foo
  • 19. Callable Type Hint <?php class Test { public function foo() {return 'foo';} static public function bar() {return 'bar';} public function __invoke(){return 'invoke';} } function run(callable $func) { echo $func(); } $o = new Test; $var = 'excepcion'; run(['Test', 'bar']); //return bar run([$o, 'foo']); //return foo run($o); //return invoke run($var); //Catchable fatal error: Argument //1 passed to run() must be callable
  • 20. Closures & $this <?php class Test { protected $name = 'Mostofreddy'; public function getName() { $callback = function() {return $this->name;}; return $callback; } } $o = new Test; $func = $o->getName(); echo $func(); //return Mostofreddy
  • 21. Closure::bindTo <?php class A { function __construct($val) {$this->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
  • 22. Class::{expr}() syntax <?php class Test { static public function foo(){ return "method foo";} static public function bar(){ return "method bar";} } $method = true; echo Test::{($method)?'foo':'bar'}(); //return method foo
  • 23. Sintaxis de array compactos //return array(6) { [0]=> <?php int(0) $array = [0, 1, 2, 3, 4]; [1]=> var_dump($array); int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) }
  • 24. Array por referencia (Array Deferencing) <?php $txt = "Erase una vez"; echo explode(" ", $txt)[0]; //return Erase echo PHP_EOL; function getName() { return array( 'usuario' => array( 'nombre'=>'Federico' ) ); } echo getName()['usuario']['nombre']; //return Federico echo PHP_EOL;
  • 26. ~/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
  • 27. ~/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
  • 29. Ejemplo simple <?php trait Log { public function addLog($m) {echo 'LOG: '.$m;} } class Test { use Log; public function foo() { $this->addLog('foo'); } } $obj = new Test; $obj->foo(); //return LOG: foo
  • 30. Multiple Traits <?php trait Log { public function addLog($m) {echo 'LOG: '.$m;} } trait Mensaje { public function holaMundo() {return "Hola Mundo!";} } class Test { use Log, Mensaje; public function foo() { $this->addLog($this->holaMundo()); } } $obj = new Test; $obj->foo(); //return LOG: Hola Mundo!
  • 31. Traits: Composicion <?php trait File { public function put($m) {error_log($m, 3, '/tmp/log');} } trait Log { use File; public function addLog($m) {$this->put('LOG: '.$m);} } class Test { use Log; public function foo() { $this->addLog('test');} } $obj = new Test; $obj->foo(); //return LOG: test
  • 32. Traits: Herencia <?php trait Hello { public function foo () {return "traits";} public function foo_1() { return $this->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
  • 33. Traits: Resolviendo conflictos <?php trait Game { public function play() {return "Play Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music; } $o = new Player; echo $o->play();
  • 34. Traits: Resolviendo conflictos <?php trait Game { public function play() {return "Play Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music; } $o = new Player; PHP no resuelve el echo $o->play(); conflicto automáticamente 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
  • 35. 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
  • 36. Traits: Resolviendo conflictos - rename <?php trait Game { public function play() {return "Play Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music { Game::play as gamePlay; Music::play insteadof Game; } } $o = new Player; echo $o->play(); //return Play Music echo $o->gamePlay(); //return Play Game
  • 37. Traits: Atributos <?php trait Usuario { protected $nombre; public function getName(){ return $this->nombre;} } class Empleado { use Usuario; public function setName($nombre) { $this->nombre = $nombre; } } $o = new Empleado; $o->setName('Federico'); echo $o->getName(); //return Federico
  • 38.
  • 39. ini options 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
  • 40. Functions & Extensiones 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)
  • 41. Para los temerosos... Tutorial para instalar de manera fácil varias versiones de PHP en un mismo servidor: http://bit.ly/HWJ5lW