SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Globalcode – Open4education
PHP 7
Incompatibilidades e mudanças de
comportamento.
Globalcode – Open4education
Sobre mim
• Primeiro contato com php em 2006.
• Técnico em processamento de dados, 2007.
• Backend PHP e nodejs.
• Integração de api’s e soluções para ecommerce.
• Chaordic/Linx
Globalcode – Open4education
20 anos do PHP
1995 - Personal Home Page Tools v1.0
1997 - PHP/fi 2
1998 - PHP 3 PHP & Zend
2000 - PHP 4 Zend engine
2004 - PHP 5 Zend Engine II
2009 - PHP 5.3 / PHP6 Unicode
2012 - PHP 5.4
2014 - PHP 5.6
2015 - PHP 7.0 Zend engine III
2016 - PHP 7.01
http://php.net/releases/
Globalcode – Open4education
Suporte
Versão Release Suporte Segurança
5.4 03/2012 09/2014 09/2015
5.5 06/2013 07/2015 07/2016
5.6 08/2014 12/2016* 12/2018*
7.0 12/2015 12/2017 12/2018
http://php.net/supported-versions.php
Globalcode – Open4education
• Mais rápido
• Menos memória
PHP7
Globalcode – Open4education
Novidades
https://wiki.php.net/rfc/abstract_syntax_tree
• Abstract Sintax Tree
Globalcode – Open4education
Novidades
https://wiki.php.net/rfc/context_sensitive_lexer
• Contexto léxico sensitivo
Globalcode – Open4education
Novidades
https://wiki.php.net/rfc/context_sensitive_lexer
• Contexto léxico sensitivo
$finder->for( ‘project’ )
->where( ‘name’ )
->or( ‘code’ )->in( [ ‘4’, ‘5’ ] );
Globalcode – Open4education
• Opcache
• Cache secundário persistente em arquivo
Novidades
http://php.net/manual/pt_BR/opcache.configuration.php
zend_extension = opcache.so
opcache.enable_cli = 1
opcache.file_cache = /tmp
opcache.file_cache_only = 1
Globalcode – Open4education
• Novos operadores
• Null coalesce
Novidades
https://wiki.php.net/rfc/isset_ternary
$x = null ?? “a” ; // “a”
$x = null ?? false ?? 1; // false
$x = null ?? “” ?? 1; // “”
$x = null ?? 0 ?? 1; // 0
Globalcode – Open4education
• Novos operadores
• Spaceship
Novidades
https://wiki.php.net/rfc/combined-comparison-operator#usefulness
[ ] <=> [ ]; // 0
[1, 2] <=> [1,1]; // 1
$a = (object) [“a” => “b”];
$b = (object) [“b” => “b”];
$a <=> $b // 0
1 <=> 1; // 0
1 <=> 2; // -1
2 <=> 1; // 1
“b” <=> “a”; // 1
“a” <=> “b”; // -1
“a” <=> “aa”; // -1
Globalcode – Open4education
• Throwable Interface
• Error
• ArithmeticError
• DivisionByZeroError
• AssertionError
• ParseError
• TypeError
• Exception
• ErrorException
Novidades
http://php.net/manual/pt_BR/language.errors.php7.php
Globalcode – Open4education
• Funções matemáticas
• Intdiv
Novidades
intdiv( 3, 2 ); // 1
intdiv( 1, 0 ); // DivisionByZeroError
intdiv( PHP_INT_MIN, -1 ); // ArithmeticError
http://php.net/manual/pt_BR/function.intdiv.php
Globalcode – Open4education
• Tipos escalares
Novidades
http://php.net/manual/en/language.types.intro.php
Globalcode – Open4education
• Tipos escalares
• Modo coercivo x estrito
Novidades
function set(string $input) : int // “1”
{
return $input; // 1
}
$output = set(1.1);
http://php.net/...migration70.new-features.scalar-type-declarations
Globalcode – Open4education
• Tipos escalares
• Modo coercivo x estrito
Novidades
declare( strict_types=1 );
function set(string $input) : int
{
return $input; //throw TypeError
}
$output = set(1.1); //throw TypeError
https://wiki.php.net/rfc/scalar_type_hints_v5#strict_types_declare_directive
Globalcode – Open4education
• Classes anônimas
• extends / implements / traits
Novidades
http://php.net/manual/pt_BR/language.oop5.anonymous.php
use packageILogger;
…
$this->setLogger(new class implements ILogger {
public function log($args){ … }
});
Globalcode – Open4education
• Constantes do tipo array
• define
Novidades
http://php.net/manual/pt_BR/migration70.new-features.php
define (“ANIMALS”, [
“dog”, “cat”, “bird”
]);
echo ANIMALS[1]; // “cat”
Globalcode – Open4education
• Unicode
• escape de strings
Novidades
// PHP 5.x
html_entity_decode(‘&#x2603’, 0, ‘UTF-8’);
mb_convert_encoding(‘&#x2603’, ‘UTF-8’, ‘HTML-ENTITIES’);
json_decode(‘“u2603”’);
// PHP 7
echo “u{2603}”; // ☃
http://php.net/manual/pt_BR/...unicode-codepoint-escape-syntax
Globalcode – Open4education
• Closure::call
Novidades
class A { private $number = 1; } // Sample class
$getCb = function( ) { return $this->number; }; // Closure
// PHP 5.6
$getNumber = $getCb->bindTo(new A, ‘A’);
echo $getNumber( ); // 1
// PHP 7
echo $getCb->call(new A); // 1
http://php.net/manual/pt_BR/closure.call.php
Globalcode – Open4education
• Agrupamento de namespaces
Novidades
use somenamespaceClassA;
use somenamespaceClassB;
use somenamespaceClassC;
use somenamespace { ClassA, ClassB, ClassC };
use function somenamespace{ fnA, fnB, fnC };
use const somenamespace { ConstA, ConstB, ConstC };
http://php.net/manual/pt_BR...group-use-declarations
Globalcode – Open4education
Globalcode – Open4education
Incompatibilidades
Globalcode – Open4education
• Variáveis variáveis
Novidades
https://wiki.php.net/rfc/isset_ternary
$foo = “bar”;
$bar = “baz”;
echo $$foo; // “baz”
Globalcode – Open4education
• Variáveis variáveis
• Sintaxe uniforme
Novidades
https://wiki.php.net/rfc/isset_ternary
$$foo[ “bar” ][ “baz” ]
$ ( $foo[ “bar” ][ “baz” ] ) // php5
$ ( $foo ) [ “bar” ][ “baz” ] // php7
Globalcode – Open4education
• Errors, handler e try/catch.
Mudanças de
comportamento
try { … }
catch(Exception $e) { … }
catch(Error $er) { … }
function errorHandler( $errno, $errstr) { ... }
set_exception_handler(‘errorHandler’);
http://php.net/manual/pt_BR/language.errors.php7.php
Globalcode – Open4education
• Parenteses redundantes.
Mudanças de
comportamento
function getArray( ) {
return [ 1, 2, 3 ];
};
function squareArray( &$a ) {
foreach( $a as &$v ) {
$v **=2;
}
}
squareArray( ( getArray( ) ) );
Notice: Only variables should be
passed by reference in /tmp/test.php
on line 13
http://php.net/manual/pt_BR/...variable-handling.parentheses
Globalcode – Open4education
• list
• Direção de leitura
Mudanças de
comportamento
list( $a[ ], $a[ ], $a[ ] ) = [ 1, 2, 3 ];
// php5
var_dump( $a ); // [ 3, 2, 1 ]
// php7
var_dump( $a ); // [ 1, 2, 3 ]
http://php.net/manual/pt_BR/...incompatible.variable-handling.list
Globalcode – Open4education
• list
• Desempacotar strings
• Chamadas vazias
Mudanças de
comportamento
$string = “abc”;
// php5
list( $a, $b, $c ) = $string; // [ ‘a’, ‘b’, ‘c’ ];
// php7
str_split( $string ); // [ ‘a’, ‘b’, ‘c’ ];
http://php.net/manual/pt_BR/...incompatible.variable-handling.list
Globalcode – Open4education
• Iterador foreach
Mudanças de
comportamento
$array = [ 0 ];
foreach( $array as &$val ) {
var_dump( &$val );
$array[ 1 ] = 1;
}
// int( 0 )
// int( 1 )
http://php.net/manual/pt_BR/...incompatible.foreach
Globalcode – Open4education
• Inteiros
• Divisão por zero
• Módulo
Mudanças de
comportamento
( 1 / 0 ); // Warning: Division by zero %s on line %d
(1 % 0); // PHP Fatal error: Uncaught DivisionByZeroError:
Module by zero in %s line %d.
http://php.net/manual/pt_BR/...incompatible.integers.div-by-zero
Globalcode – Open4education
• Palavras reservadas
• int, float, bool, string
• resource, object, mixed, numeric
Mudanças de
comportamento
class string { // ParseError
...
}
http://php.net/manual/pt_BR/reserved.other-reserved-words.php
Globalcode – Open4education
• Construtores do php 4
Depreciados
class Example
{
// php 4 style
public function Example ( ) { ... }
// php 5 style
public function __construct ( ) { ... }
}
http://php.net/manual/pt_BR/...deprecated.php4-constructors
Globalcode – Open4education
• Chamadas estáticas a não estáticos de outro
contexto
Depreciados
class A {
public function test( ) { var_dump( $this ); };
}
class B {
public function callNonStaticOfA( ) { A::test( ); }
}
(new B)->callNonStaticOfA( ); // Undefined variable
http://php.net/manual/pt_BR/...deprecated.static-calls
Globalcode – Open4education
• mysql
• mysqli ou pdo
• ereg
• preg
• call_user_method( )
• call_user_func( )
• call_user_method_array()
• call_user_func_array( )
Removidos:
http://php.net/manual/pt_BR/migration70.removed-exts-sapis.php
Globalcode – Open4education
• Instalar Virtualbox e Vagrant
• Clonar repositório
Testando o php 7
$ git clone https://github.com/rlerdorf/php7dev.git
$ cd php7dev
$ vagrant up
$ vagrant ssh
Globalcode – Open4education
Importância de testes
Globalcode – Open4education
• Slides palestra Rasmus
• http://talks.php.net/tokyo15#/
• Guia de migração(Manual PHP)
• http://php.net/manual/pt_BR/migration70.php
• Zend infográficos e novidades
• http://www.zend.com/en/resources/php7_infographic
• http://www.zend.com/en/resources/php7-5-things-to-know-infographic
Referências
Globalcode – Open4education
• Email: mbaymone@gmail.com
• twitter: @mbaymone
• Facebook: facebook.com/mbertholdt
• LinkedIn: linkedin.com/in/marceloaymone
• Github: github.com/aymone
Contato
Globalcode – Open4education
Obrigado!!!

Mais conteúdo relacionado

Destaque

Abdominal auscultation [2015]
Abdominal auscultation [2015]Abdominal auscultation [2015]
Abdominal auscultation [2015]Ayman Alsebaey
 
4th evaluation question
4th evaluation question4th evaluation question
4th evaluation questionajones112
 
Haploid induction of allelic diversity populations in maize
Haploid induction of allelic diversity populations in maizeHaploid induction of allelic diversity populations in maize
Haploid induction of allelic diversity populations in maizeNaveen Jakhar
 
Dhcp server &amp; dns server
Dhcp server &amp; dns serverDhcp server &amp; dns server
Dhcp server &amp; dns serverAgus60
 
Scout - How Create Successful Brand Protection Program
Scout - How Create Successful Brand Protection ProgramScout - How Create Successful Brand Protection Program
Scout - How Create Successful Brand Protection ProgramFākR™
 
2015 bocoor power bank pricelist
2015 bocoor power bank pricelist2015 bocoor power bank pricelist
2015 bocoor power bank pricelistBOCOOR
 
Abdominal percussion [2015]
Abdominal percussion [2015]Abdominal percussion [2015]
Abdominal percussion [2015]Ayman Alsebaey
 
An Intra-oral Cement Control System. A Great Solution to a Big Problem
An Intra-oral Cement Control System. A Great Solution to a Big ProblemAn Intra-oral Cement Control System. A Great Solution to a Big Problem
An Intra-oral Cement Control System. A Great Solution to a Big ProblemEmil Svoboda
 
[2015] the treatment of diabetes mellitus of patients with chronic liver disease
[2015] the treatment of diabetes mellitus of patients with chronic liver disease[2015] the treatment of diabetes mellitus of patients with chronic liver disease
[2015] the treatment of diabetes mellitus of patients with chronic liver diseaseAyman Alsebaey
 
Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...
Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...
Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...Emil Svoboda
 
Screw versus cement for implant prosthesis installation part 2
Screw versus cement for implant prosthesis installation part 2Screw versus cement for implant prosthesis installation part 2
Screw versus cement for implant prosthesis installation part 2Emil Svoboda
 
Cytomegalovirus (cmv), the hidden enemy in liver transplantation 2015
Cytomegalovirus (cmv), the hidden enemy in liver   transplantation 2015Cytomegalovirus (cmv), the hidden enemy in liver   transplantation 2015
Cytomegalovirus (cmv), the hidden enemy in liver transplantation 2015Ayman Alsebaey
 
Cabbage (Brassica oleracea var.capitata)
Cabbage (Brassica oleracea var.capitata)Cabbage (Brassica oleracea var.capitata)
Cabbage (Brassica oleracea var.capitata)Naveen Jakhar
 
[2016] pathogenesis of liver fibrosis
[2016] pathogenesis of liver fibrosis[2016] pathogenesis of liver fibrosis
[2016] pathogenesis of liver fibrosisAyman Alsebaey
 
[2015] hcv direct acting antivirals [da as] stumbling
[2015] hcv direct acting antivirals [da as] stumbling[2015] hcv direct acting antivirals [da as] stumbling
[2015] hcv direct acting antivirals [da as] stumblingAyman Alsebaey
 

Destaque (20)

Aula 1
Aula 1Aula 1
Aula 1
 
My Cv Cristina Galo
My Cv Cristina GaloMy Cv Cristina Galo
My Cv Cristina Galo
 
Abdominal auscultation [2015]
Abdominal auscultation [2015]Abdominal auscultation [2015]
Abdominal auscultation [2015]
 
Doa damai
Doa damaiDoa damai
Doa damai
 
PPP Jeffrey Kaney
PPP Jeffrey KaneyPPP Jeffrey Kaney
PPP Jeffrey Kaney
 
4th evaluation question
4th evaluation question4th evaluation question
4th evaluation question
 
Haploid induction of allelic diversity populations in maize
Haploid induction of allelic diversity populations in maizeHaploid induction of allelic diversity populations in maize
Haploid induction of allelic diversity populations in maize
 
My Cv Cristina Galo
My Cv Cristina GaloMy Cv Cristina Galo
My Cv Cristina Galo
 
Dhcp server &amp; dns server
Dhcp server &amp; dns serverDhcp server &amp; dns server
Dhcp server &amp; dns server
 
Scout - How Create Successful Brand Protection Program
Scout - How Create Successful Brand Protection ProgramScout - How Create Successful Brand Protection Program
Scout - How Create Successful Brand Protection Program
 
2015 bocoor power bank pricelist
2015 bocoor power bank pricelist2015 bocoor power bank pricelist
2015 bocoor power bank pricelist
 
Abdominal percussion [2015]
Abdominal percussion [2015]Abdominal percussion [2015]
Abdominal percussion [2015]
 
An Intra-oral Cement Control System. A Great Solution to a Big Problem
An Intra-oral Cement Control System. A Great Solution to a Big ProblemAn Intra-oral Cement Control System. A Great Solution to a Big Problem
An Intra-oral Cement Control System. A Great Solution to a Big Problem
 
[2015] the treatment of diabetes mellitus of patients with chronic liver disease
[2015] the treatment of diabetes mellitus of patients with chronic liver disease[2015] the treatment of diabetes mellitus of patients with chronic liver disease
[2015] the treatment of diabetes mellitus of patients with chronic liver disease
 
Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...
Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...
Screw versus Cement for Implant Prosthesis Installation. Part 2: The Game Cha...
 
Screw versus cement for implant prosthesis installation part 2
Screw versus cement for implant prosthesis installation part 2Screw versus cement for implant prosthesis installation part 2
Screw versus cement for implant prosthesis installation part 2
 
Cytomegalovirus (cmv), the hidden enemy in liver transplantation 2015
Cytomegalovirus (cmv), the hidden enemy in liver   transplantation 2015Cytomegalovirus (cmv), the hidden enemy in liver   transplantation 2015
Cytomegalovirus (cmv), the hidden enemy in liver transplantation 2015
 
Cabbage (Brassica oleracea var.capitata)
Cabbage (Brassica oleracea var.capitata)Cabbage (Brassica oleracea var.capitata)
Cabbage (Brassica oleracea var.capitata)
 
[2016] pathogenesis of liver fibrosis
[2016] pathogenesis of liver fibrosis[2016] pathogenesis of liver fibrosis
[2016] pathogenesis of liver fibrosis
 
[2015] hcv direct acting antivirals [da as] stumbling
[2015] hcv direct acting antivirals [da as] stumbling[2015] hcv direct acting antivirals [da as] stumbling
[2015] hcv direct acting antivirals [da as] stumbling
 

Semelhante a TDC 2016 - PHP7

Pense no futuro: PHP com Zend Framework
Pense no futuro: PHP com Zend FrameworkPense no futuro: PHP com Zend Framework
Pense no futuro: PHP com Zend FrameworkFlávio Lisboa
 
PHP Experience 2016 - [Palestra] Keynote: PHP-7
PHP Experience 2016 - [Palestra] Keynote: PHP-7PHP Experience 2016 - [Palestra] Keynote: PHP-7
PHP Experience 2016 - [Palestra] Keynote: PHP-7iMasters
 
5 Maneiras de melhorar seu código PHP
5 Maneiras de melhorar seu código PHP5 Maneiras de melhorar seu código PHP
5 Maneiras de melhorar seu código PHPAugusto das Neves
 
Palestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAPalestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAThiago Cifani
 
PHP para aplicações Web de grande porte
PHP para aplicações Web  de grande portePHP para aplicações Web  de grande porte
PHP para aplicações Web de grande porteFelipe Ribeiro
 
Cakephp - framework de desenvolvimento de aplicações Web em PHP
Cakephp - framework de desenvolvimento de aplicações Web em PHPCakephp - framework de desenvolvimento de aplicações Web em PHP
Cakephp - framework de desenvolvimento de aplicações Web em PHPArlindo Santos
 
Xdebug seus problemas acabaram - tdc floripa 2017
Xdebug   seus problemas acabaram - tdc floripa 2017Xdebug   seus problemas acabaram - tdc floripa 2017
Xdebug seus problemas acabaram - tdc floripa 2017Vitor Mattos
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...tdc-globalcode
 
O Aduino ama a Internet - TDC 2012
O Aduino ama a Internet - TDC 2012O Aduino ama a Internet - TDC 2012
O Aduino ama a Internet - TDC 2012Marco Antonio Maciel
 
Logs, pra que te quero! @ PHP Community Summit by locaweb 2017
Logs, pra que te quero! @ PHP Community Summit by locaweb 2017Logs, pra que te quero! @ PHP Community Summit by locaweb 2017
Logs, pra que te quero! @ PHP Community Summit by locaweb 2017Gabriel Machado
 

Semelhante a TDC 2016 - PHP7 (20)

PHP 7 - A Maioridade do PHP
PHP 7 - A Maioridade do PHPPHP 7 - A Maioridade do PHP
PHP 7 - A Maioridade do PHP
 
Pense no futuro: PHP com Zend Framework
Pense no futuro: PHP com Zend FrameworkPense no futuro: PHP com Zend Framework
Pense no futuro: PHP com Zend Framework
 
Mini Curso de PHP
Mini Curso de PHPMini Curso de PHP
Mini Curso de PHP
 
Linguagem PHP
Linguagem PHPLinguagem PHP
Linguagem PHP
 
PHP 7
PHP 7PHP 7
PHP 7
 
PHP Experience 2016 - [Palestra] Keynote: PHP-7
PHP Experience 2016 - [Palestra] Keynote: PHP-7PHP Experience 2016 - [Palestra] Keynote: PHP-7
PHP Experience 2016 - [Palestra] Keynote: PHP-7
 
5 Maneiras de melhorar seu código PHP
5 Maneiras de melhorar seu código PHP5 Maneiras de melhorar seu código PHP
5 Maneiras de melhorar seu código PHP
 
Palestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAPalestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVA
 
Modern PHP
Modern PHPModern PHP
Modern PHP
 
Sapo Sessions PHP
Sapo Sessions PHPSapo Sessions PHP
Sapo Sessions PHP
 
PHP para aplicações Web de grande porte
PHP para aplicações Web  de grande portePHP para aplicações Web  de grande porte
PHP para aplicações Web de grande porte
 
Cakephp - framework de desenvolvimento de aplicações Web em PHP
Cakephp - framework de desenvolvimento de aplicações Web em PHPCakephp - framework de desenvolvimento de aplicações Web em PHP
Cakephp - framework de desenvolvimento de aplicações Web em PHP
 
PHP Tools for Fast coding
PHP Tools for Fast codingPHP Tools for Fast coding
PHP Tools for Fast coding
 
Novidades do PHP 5.3 e 6
Novidades do PHP 5.3 e 6Novidades do PHP 5.3 e 6
Novidades do PHP 5.3 e 6
 
Xdebug seus problemas acabaram - tdc floripa 2017
Xdebug   seus problemas acabaram - tdc floripa 2017Xdebug   seus problemas acabaram - tdc floripa 2017
Xdebug seus problemas acabaram - tdc floripa 2017
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
O Aduino ama a Internet - TDC 2012
O Aduino ama a Internet - TDC 2012O Aduino ama a Internet - TDC 2012
O Aduino ama a Internet - TDC 2012
 
Dev Ext PHP
Dev Ext PHPDev Ext PHP
Dev Ext PHP
 
Logs, pra que te quero! @ PHP Community Summit by locaweb 2017
Logs, pra que te quero! @ PHP Community Summit by locaweb 2017Logs, pra que te quero! @ PHP Community Summit by locaweb 2017
Logs, pra que te quero! @ PHP Community Summit by locaweb 2017
 
Security & PHP
Security & PHPSecurity & PHP
Security & PHP
 

TDC 2016 - PHP7

  • 1. Globalcode – Open4education PHP 7 Incompatibilidades e mudanças de comportamento.
  • 2. Globalcode – Open4education Sobre mim • Primeiro contato com php em 2006. • Técnico em processamento de dados, 2007. • Backend PHP e nodejs. • Integração de api’s e soluções para ecommerce. • Chaordic/Linx
  • 3. Globalcode – Open4education 20 anos do PHP 1995 - Personal Home Page Tools v1.0 1997 - PHP/fi 2 1998 - PHP 3 PHP & Zend 2000 - PHP 4 Zend engine 2004 - PHP 5 Zend Engine II 2009 - PHP 5.3 / PHP6 Unicode 2012 - PHP 5.4 2014 - PHP 5.6 2015 - PHP 7.0 Zend engine III 2016 - PHP 7.01 http://php.net/releases/
  • 4. Globalcode – Open4education Suporte Versão Release Suporte Segurança 5.4 03/2012 09/2014 09/2015 5.5 06/2013 07/2015 07/2016 5.6 08/2014 12/2016* 12/2018* 7.0 12/2015 12/2017 12/2018 http://php.net/supported-versions.php
  • 5. Globalcode – Open4education • Mais rápido • Menos memória PHP7
  • 8. Globalcode – Open4education Novidades https://wiki.php.net/rfc/context_sensitive_lexer • Contexto léxico sensitivo $finder->for( ‘project’ ) ->where( ‘name’ ) ->or( ‘code’ )->in( [ ‘4’, ‘5’ ] );
  • 9. Globalcode – Open4education • Opcache • Cache secundário persistente em arquivo Novidades http://php.net/manual/pt_BR/opcache.configuration.php zend_extension = opcache.so opcache.enable_cli = 1 opcache.file_cache = /tmp opcache.file_cache_only = 1
  • 10. Globalcode – Open4education • Novos operadores • Null coalesce Novidades https://wiki.php.net/rfc/isset_ternary $x = null ?? “a” ; // “a” $x = null ?? false ?? 1; // false $x = null ?? “” ?? 1; // “” $x = null ?? 0 ?? 1; // 0
  • 11. Globalcode – Open4education • Novos operadores • Spaceship Novidades https://wiki.php.net/rfc/combined-comparison-operator#usefulness [ ] <=> [ ]; // 0 [1, 2] <=> [1,1]; // 1 $a = (object) [“a” => “b”]; $b = (object) [“b” => “b”]; $a <=> $b // 0 1 <=> 1; // 0 1 <=> 2; // -1 2 <=> 1; // 1 “b” <=> “a”; // 1 “a” <=> “b”; // -1 “a” <=> “aa”; // -1
  • 12. Globalcode – Open4education • Throwable Interface • Error • ArithmeticError • DivisionByZeroError • AssertionError • ParseError • TypeError • Exception • ErrorException Novidades http://php.net/manual/pt_BR/language.errors.php7.php
  • 13. Globalcode – Open4education • Funções matemáticas • Intdiv Novidades intdiv( 3, 2 ); // 1 intdiv( 1, 0 ); // DivisionByZeroError intdiv( PHP_INT_MIN, -1 ); // ArithmeticError http://php.net/manual/pt_BR/function.intdiv.php
  • 14. Globalcode – Open4education • Tipos escalares Novidades http://php.net/manual/en/language.types.intro.php
  • 15. Globalcode – Open4education • Tipos escalares • Modo coercivo x estrito Novidades function set(string $input) : int // “1” { return $input; // 1 } $output = set(1.1); http://php.net/...migration70.new-features.scalar-type-declarations
  • 16. Globalcode – Open4education • Tipos escalares • Modo coercivo x estrito Novidades declare( strict_types=1 ); function set(string $input) : int { return $input; //throw TypeError } $output = set(1.1); //throw TypeError https://wiki.php.net/rfc/scalar_type_hints_v5#strict_types_declare_directive
  • 17. Globalcode – Open4education • Classes anônimas • extends / implements / traits Novidades http://php.net/manual/pt_BR/language.oop5.anonymous.php use packageILogger; … $this->setLogger(new class implements ILogger { public function log($args){ … } });
  • 18. Globalcode – Open4education • Constantes do tipo array • define Novidades http://php.net/manual/pt_BR/migration70.new-features.php define (“ANIMALS”, [ “dog”, “cat”, “bird” ]); echo ANIMALS[1]; // “cat”
  • 19. Globalcode – Open4education • Unicode • escape de strings Novidades // PHP 5.x html_entity_decode(‘&#x2603’, 0, ‘UTF-8’); mb_convert_encoding(‘&#x2603’, ‘UTF-8’, ‘HTML-ENTITIES’); json_decode(‘“u2603”’); // PHP 7 echo “u{2603}”; // ☃ http://php.net/manual/pt_BR/...unicode-codepoint-escape-syntax
  • 20. Globalcode – Open4education • Closure::call Novidades class A { private $number = 1; } // Sample class $getCb = function( ) { return $this->number; }; // Closure // PHP 5.6 $getNumber = $getCb->bindTo(new A, ‘A’); echo $getNumber( ); // 1 // PHP 7 echo $getCb->call(new A); // 1 http://php.net/manual/pt_BR/closure.call.php
  • 21. Globalcode – Open4education • Agrupamento de namespaces Novidades use somenamespaceClassA; use somenamespaceClassB; use somenamespaceClassC; use somenamespace { ClassA, ClassB, ClassC }; use function somenamespace{ fnA, fnB, fnC }; use const somenamespace { ConstA, ConstB, ConstC }; http://php.net/manual/pt_BR...group-use-declarations
  • 24. Globalcode – Open4education • Variáveis variáveis Novidades https://wiki.php.net/rfc/isset_ternary $foo = “bar”; $bar = “baz”; echo $$foo; // “baz”
  • 25. Globalcode – Open4education • Variáveis variáveis • Sintaxe uniforme Novidades https://wiki.php.net/rfc/isset_ternary $$foo[ “bar” ][ “baz” ] $ ( $foo[ “bar” ][ “baz” ] ) // php5 $ ( $foo ) [ “bar” ][ “baz” ] // php7
  • 26. Globalcode – Open4education • Errors, handler e try/catch. Mudanças de comportamento try { … } catch(Exception $e) { … } catch(Error $er) { … } function errorHandler( $errno, $errstr) { ... } set_exception_handler(‘errorHandler’); http://php.net/manual/pt_BR/language.errors.php7.php
  • 27. Globalcode – Open4education • Parenteses redundantes. Mudanças de comportamento function getArray( ) { return [ 1, 2, 3 ]; }; function squareArray( &$a ) { foreach( $a as &$v ) { $v **=2; } } squareArray( ( getArray( ) ) ); Notice: Only variables should be passed by reference in /tmp/test.php on line 13 http://php.net/manual/pt_BR/...variable-handling.parentheses
  • 28. Globalcode – Open4education • list • Direção de leitura Mudanças de comportamento list( $a[ ], $a[ ], $a[ ] ) = [ 1, 2, 3 ]; // php5 var_dump( $a ); // [ 3, 2, 1 ] // php7 var_dump( $a ); // [ 1, 2, 3 ] http://php.net/manual/pt_BR/...incompatible.variable-handling.list
  • 29. Globalcode – Open4education • list • Desempacotar strings • Chamadas vazias Mudanças de comportamento $string = “abc”; // php5 list( $a, $b, $c ) = $string; // [ ‘a’, ‘b’, ‘c’ ]; // php7 str_split( $string ); // [ ‘a’, ‘b’, ‘c’ ]; http://php.net/manual/pt_BR/...incompatible.variable-handling.list
  • 30. Globalcode – Open4education • Iterador foreach Mudanças de comportamento $array = [ 0 ]; foreach( $array as &$val ) { var_dump( &$val ); $array[ 1 ] = 1; } // int( 0 ) // int( 1 ) http://php.net/manual/pt_BR/...incompatible.foreach
  • 31. Globalcode – Open4education • Inteiros • Divisão por zero • Módulo Mudanças de comportamento ( 1 / 0 ); // Warning: Division by zero %s on line %d (1 % 0); // PHP Fatal error: Uncaught DivisionByZeroError: Module by zero in %s line %d. http://php.net/manual/pt_BR/...incompatible.integers.div-by-zero
  • 32. Globalcode – Open4education • Palavras reservadas • int, float, bool, string • resource, object, mixed, numeric Mudanças de comportamento class string { // ParseError ... } http://php.net/manual/pt_BR/reserved.other-reserved-words.php
  • 33. Globalcode – Open4education • Construtores do php 4 Depreciados class Example { // php 4 style public function Example ( ) { ... } // php 5 style public function __construct ( ) { ... } } http://php.net/manual/pt_BR/...deprecated.php4-constructors
  • 34. Globalcode – Open4education • Chamadas estáticas a não estáticos de outro contexto Depreciados class A { public function test( ) { var_dump( $this ); }; } class B { public function callNonStaticOfA( ) { A::test( ); } } (new B)->callNonStaticOfA( ); // Undefined variable http://php.net/manual/pt_BR/...deprecated.static-calls
  • 35. Globalcode – Open4education • mysql • mysqli ou pdo • ereg • preg • call_user_method( ) • call_user_func( ) • call_user_method_array() • call_user_func_array( ) Removidos: http://php.net/manual/pt_BR/migration70.removed-exts-sapis.php
  • 36. Globalcode – Open4education • Instalar Virtualbox e Vagrant • Clonar repositório Testando o php 7 $ git clone https://github.com/rlerdorf/php7dev.git $ cd php7dev $ vagrant up $ vagrant ssh
  • 38. Globalcode – Open4education • Slides palestra Rasmus • http://talks.php.net/tokyo15#/ • Guia de migração(Manual PHP) • http://php.net/manual/pt_BR/migration70.php • Zend infográficos e novidades • http://www.zend.com/en/resources/php7_infographic • http://www.zend.com/en/resources/php7-5-things-to-know-infographic Referências
  • 39. Globalcode – Open4education • Email: mbaymone@gmail.com • twitter: @mbaymone • Facebook: facebook.com/mbertholdt • LinkedIn: linkedin.com/in/marceloaymone • Github: github.com/aymone Contato