5. @felixgomezlopez
1995-2016 (21 YEARS OF PHP)
Version Release date
Personal Homepage Tools (PHP Tools) Version 1.0
PHP/FI 2
June 8th
1995
November 1997
PHP 3 June 1998
PHP 4 May 2000
PHP 5 July 2004
PHP 5.3/5.4 June 2009
PHP 7 December 2015
= PHP 6 - UNICODE
6. @felixgomezlopez
¿QUÉ FUE DE PHP6?
https://wiki.php.net/rfc/php6
● Intento fallido de salto de versión
● Iniciado en 2005 y finalizado en 2010
● Se integraron features en PHP 5.3 y 5.4
● Después de descartar UTF-16, intl se distribuyó como parte de PHP 5.3
y exponía las funcionalidades de la librería ICU.
● Se llegaron a publicar libros y se dieron charlas, pero nunca vió la luz
7. @felixgomezlopez
CRONOLOGíA PHP (21 AÑOS)
Versión Tiempo de vida
Personal Homepage Tools (PHP Tools) Version 1.0
PHP/FI 2
~ 2 años
~ 1 año
PHP 3 ~ 2 años
PHP 4 ~ 2 años
PHP 5 ~ 11 años
11. @felixgomezlopez
¿SOBRE QUÉ SE BASA?
https://drive.google.
com/file/d/0B3UKOMH_4lgBUTdjUGxIZ3l1Ukk/view?usp=sharing
● Refactoring
● Objetivo principal: Alcanzar un nuevo nivel de rendimiento y
hacerlo base para futuras releases
● Separado de la rama principal de PHP en Enero de 2014
● Sin cambios para el usuario (solo cambios internos)
12. @felixgomezlopez
ESTADO DE PHPNG
● Llevó 2 semanas compilar el core
● En dos semanas más podía correr bench.php
● Después de mes y medio compatible con WordPress
● Se abre el proyecto 1 mes después (principios de mayo)
● Se mergea a master como base para PHP7 en Agosto de 2014
24. @felixgomezlopez
CÓDIGO PHP SCANNING
(a.k.a. LEXING)
PARSING
Tokens
● Elimina espacios en blanco
● Se queda con expresiones irreducibles del
conjunto de tokens
PARSING (PHP 5)
<?php
echo "Hello World";
$a = 1 + 1;
echo $a;
1. mostrar string
2. sumar dos números
3. guardar el resultado de la operación anterior en una
variable
4. mostrar la variable
28. @felixgomezlopez
PHP 7: VENTAJAS ABSTRACT SYNTAX TREE (AST)
● Permite añadir funcionalidades más fácilmente
● Consistencia en la interpretación
● Mejora en rendimiento
● Permite que el lenguaje sea más flexible
Posibilidades “SCI-FI”
● Posibilidad de conversión inversa por análisis de AST->SOURCE CODE
● Posibilidad de generar AST externo para ser compilado por Zend
Engine 3
29. @felixgomezlopez
[$x*2 foreach(range(0,10) as $x)]
http://twig.sensiolabs.org/doc/internals.html
[x*2 for x in range(10)]
PHP 7: POSIBILITIES ABSTRACT SYNTAX TREE (AST)
http://docs.hylang.org/en/latest/
39. @felixgomezlopez
RETURN TYPE DECLARATIONS (TIPOS DE RETORNO)
<?php
// Returned type does not match the type declaration
function get_config(): array {
return 42;
}
get_config();
Fatal error: Uncaught TypeError: Return value of get_config() must be of the
type array, integer returned in /home/vagrant/Lab/index.php:6
Stack trace:
#0 /home/vagrant/Lab/index.php(9): get_config()
#1 {main}
thrown in /home/vagrant/Lab/index.php on line 6
44. @felixgomezlopez
Fatal error: Uncaught TypeError: Argument 1 passed to add()
must be of the type integer, string given, called in
/home/vagrant/Lab/index.php on line 10 and defined in
/home/vagrant/Lab/index.php:5
Stack trace:
#0 /home/vagrant/Lab/index.php(10): add('2', '2')
#1 {main}
thrown in /home/vagrant/Lab/index.php on line 5
SCALAR TYPE DECLARATIONS
46. @felixgomezlopez
SCALAR TYPE DECLARATIONS
Fatal error: Uncaught TypeError: Return value of foo() must
be of the type boolean, integer returned in
/home/vagrant/Lab/index.php:5
Stack trace:
#0 /home/vagrant/Lab/index.php(8): foo()
#1 {main}
thrown in /home/vagrant/Lab/index.php on line 5
55. @felixgomezlopez
ANONYMOUS CLASSES
<?php
// PHP 5.x
class MyLogger {
public function log($msg) {
print_r($msg . "n");
}
}
$pusher->setLogger( new MyLogger() );
// New Hotness
$pusher->setLogger(new class {
public function log($msg) {
print_r($msg . "n");
}
});
57. @felixgomezlopez
GROUP USE DECLARATIONS
use SymfonyComponentFormForm;
use SymfonyComponentFormFormError;
use TalkTalkDb;
use TalkTalkApi;
use UserUserDb;
use UserUserApi;
use SymfonyComponentForm{Form, FormError};
use Talk{TalkDb, TalkApi};
use User{UserDb, UserApi};
PHP5
PHP7
60. @felixgomezlopez
UNIFORM VARIABLE SYNTAX (CONT.)
// old meaning // new meaning
$$foo['bar']['baz'] ${$foo['bar']['baz']} ($$foo)['bar']['baz']
$foo->$bar['baz'] $foo->{$bar['baz']} ($foo->$bar)['baz']
$foo->$bar['baz']() $foo->{$bar['baz']}() ($foo->$bar)['baz']()
Foo::$bar['baz']() Foo::{$bar['baz']}() (Foo::$bar)['baz']()
Ante la duda paréntesis!
62. @felixgomezlopez
UNIFORM VARIABLE SYNTAX (CONT.)
// support operations on arbitrary (...) expressions
(...)['foo']
(...)->foo
(...)->foo()
(...)::$foo
(...)::foo()
(...)()
// two more practical examples for the last point
(function() { ... })()
($obj->closure)()
69. @felixgomezlopez
REMOVE ALTERNATIVE PHP TAGS
● <% opening tag
● <%= opening tag with echo
● %> closing tag
● (<scripts+languages*=s*(php|"php"|'php')s*>)i
opening tag
● (</script>)i closing tag
76. @felixgomezlopez
<?php
class Filter
{
// PHP 5: filter is a constructor
// PHP 7: filter is a constructor and E_DEPRECATED is raised
// PHP 8: filter is a normal method and is not a constructor;
no E_DEPRECATED is raised
function filter($a) {}
}
$filter = new ReflectionMethod('Filter', 'filter');
// PHP 5: bool(true)
// PHP 7: bool(true)
// PHP 8: bool(false)
var_dump($filter->isConstructor());
“REMOVAL” OF PHP4 CONSTRUCTORS
77. @felixgomezlopez
<?php
// function filter is not used as constructor in PHP 5+
class Filter
{
// PHP 5: E_STRICT "Redefining already defined
constructor"
// PHP 7: No error is raised
// PHP 8: No error is raised
function __construct() {}
function filter($a) {}
}
“REMOVAL” OF PHP4 CONSTRUCTORS
78. @felixgomezlopez
<?php
// function filter is not used as constructor in PHP 5+
class Filter {
function __construct() {}
// PHP 5.0.0 - 5.2.13, 5.3.0 - 5.3.2: E_STRICT "Redefining
already defined constructor"
// PHP 5.2.14 - 5.2.17, 5.3.3 - 5.6: No error is raised
// PHP 7: No error is raised
// PHP 8: No error is raised
function filter($a) {}
}
REMOVAL OF PHP4 CONSTRUCTORS
79. @felixgomezlopez
class Filter
{
// PHP 5: filter is a constructor
// PHP 7: filter is a constructor and E_DEPRECATED is raised
// PHP 8: filter is a normal method and is not a constructor; no E_DEPRECATED
is raised
function filter() {}
}
class FilterX extends Filter
{
function __construct(){
// PHP 5: Filter::filter is called; no error
// PHP 7: Filter::filter is called; no error
// PHP 8: "Fatal error: Cannot call constructor"
parent::__construct();
}
}
new FilterX();
“REMOVAL” OF PHP4 CONSTRUCTORS
Félix Gómez López - Freelance Web developer
Físico de formación.
Ex-profesor de FP
Desarrollador web desde hace más de 10 años.
Actualmente desarrollando proyectos a medida basados en
Symfony2/3
AngularJS
NodeJS
MongoDB
Ionic