Upload
er-galvao-abbott
View
1.245
Download
5
Embed Size (px)
Citation preview
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 1 / 38
Tudo o que você precisa saber sobre PHP7 www.galvao.eti.br
Tudo o que você precisasaber sobre
PHP7 Logo by Vincent Pontier, Freddie and other silly things by The Internet
Presidente da ABRAPHP – Associação Brasileira de Profissionais PHPDiretor da PHP Conference BrasilContribui para a tradução da documentação oficial Atua como Zend Framework Evangelist para o ZTeam, da Zend.
20+ anos desenvolvendo sistemas e aplicações com interface web 15+ destes com PHP 7+ com Zend Framework
Palestrante em eventos nacionais e internacionaisInstrutor de cursos presenciais e a distânciaFundador e líder do GU PHPBRFundador* e membro do GU PHPRS
Site: http://www.galvao.eti.br/ http://people.php.net/galvaoTwitter: @galvaoSlides e Documentos: http://slideshare.net/ergalvao https://speakerdeck.com/galvaoGithub: http://github.com/galvaoPosts: https://medium.com/@galvao
Quem?!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 2 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
Sumário
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 3 / 38
www.galvao.eti.br
F.A.Q.
Tudo o que você precisa saber sobre PHP7
Spaceship OperatorNULL Coalesce OperatorGroup Use DeclarationsScalar Type Hints Return Type DeclarationsExceptions in the engineCSPRNGArrays Constantes
R.I.P.mysqlTagsConstrutor estilo PHP4
Features
Velozes & Curiosos
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 4 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
≃3x mais rápido (no mínimo)
Escolha seu benchmark favorito:
- Google Spreadsheet, by Dmitry Stogov (Zend)- Artigo, by Lorna Jane- Infográficos, by Zend
- Método ninja para encontrar benchmarks de PHP7
F.A.Q.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 5 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
PHP6?
F.A.Q.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 6 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
ISSO NON EXZISTE!
PHP6?
F.A.Q.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 7 / 38
www.galvao.eti.br
https://github.com/rlerdorf/php7dev
Quero agora!
Tudo o que você precisa saber sobre PHP7
F.A.Q.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 8 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
F.A.Q.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 9 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
X
F.A.Q.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 10 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
https://wiki.php.net/rfc
Karma
RFC Debate
Mudanças
Votação
Aprovação
Rejeição*
Spaceship Operator
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 11 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 12 / 38
www.galvao.eti.br
1 <=> 0 → 1
Pew!
Tudo o que você precisa saber sobre PHP7
Spaceship Operator
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 13 / 38
www.galvao.eti.br
1 <=> 0 → 11 <=> 1 → 0
Pew!
Pew!
Tudo o que você precisa saber sobre PHP7
Spaceship Operator
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 14 / 38
www.galvao.eti.br
1 <=> 0 → 11 <=> 1 → 00 <=> 1 → -1
Pew!
Pew!
Pew!
Tudo o que você precisa saber sobre PHP7
Spaceship Operator
NULL Coalesce Operator
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 15 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
$foo = isset($_GET['bar']) ? $_GET['bar'] : true;
$foo = $_GET['bar'] ?? true;
PHP5
PHP7
Group Use Declarations
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 16 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
PHP5
PHP7
use Foo\Bar;use Foo\Baz;use Foo\Quux;
use Foo\{Bar, Baz, Quux};
use Foo\{ Bar\Thud, Baz\Grunt\Bletch, Quux\Fum};
STH
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 17 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpfunction foo(int $x, int $y){ return $x + $y;}
echo foo('1', 2);
Coercive
Resultado: 3
STH
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 18 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpdeclare(strict_types=1);
function foo(int $x, int $y){ return $x + $y;}
echo foo('1', 2);
Strict
STH
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 19 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
Resultado:
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type integer, string given, called in /home/vagrant/php7tests/t1.php on line 9 and defined in /home/vagrant/php7tests/t1.php:4
Stack trace:#0 /home/vagrant/php7tests/t1.php(9): foo('1', 2)#1 {main} thrown in /home/vagrant/php7tests/t1.php on line 4
STH
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 20 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
Resultado:
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type integer, string given, called in /home/vagrant/php7tests/t1.php on line 9 and defined in /home/vagrant/php7tests/t1.php:4
Stack trace:#0 /home/vagrant/php7tests/t1.php(9): foo('1', 2)#1 {main} thrown in /home/vagrant/php7tests/t1.php on line 4
Return Type Declarations
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 21 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpfunction foo($x,$y):int{ return (string)($x + $y);}
echo foo(1, 2);
Resultado: 3
Coercive
Return Type Declarations
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 22 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpdeclare(strict_types=1);
function foo($x,$y):int{ return (string)($x + $y);}
echo foo(1, 2);
Strict
Return Type Declarations
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 23 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
Resultado:
Fatal error: Uncaught TypeError: Return value of foo() must be of the type integer, string returned in /home/vagrant/php7tests/t2.php:6
Stack trace:#0 /home/vagrant/php7tests/t2.php(9): foo(1, 2)#1 {main} thrown in /home/vagrant/php7tests/t2.php on line 6
Return Type Declarations
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 24 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
Resultado:
Fatal error: Uncaught TypeError: Return value of foo() must be of the type integer, string returned in /home/vagrant/php7tests/t2.php:6
Stack trace:#0 /home/vagrant/php7tests/t2.php(9): foo(1, 2)#1 {main} thrown in /home/vagrant/php7tests/t2.php on line 6
Exceptions in the Engine
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 25 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?php$foo = 0;
try { $foo->bar();} catch (Throwable $e) { die($e->getMessage());}
Exceptions in the Engine
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 26 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpdeclare(strict_types=1);
function foo($x,$y):int{ return (string)($x + $y);}
try { echo foo(1, 2);} catch (TypeError $e) { die($e->getMessage());}
CSPRNG
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 27 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
string random_bytes(int $length)
int random_int(int $min, int $max)
Facilitar o acesso a Criptografia!
Lançam uma Error Exception se a aleatoriedade for insuficiente
Arrays Constantes
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 28 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpdefine('DB_USER', 'foo');define('DB_PASS', 'bar');define('DB_HOST', 'localhost');define('DB_NAME', 'baz');define('DB_PORT', 3306);
PHP5
Arrays Constantes
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 29 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<?phpdefine('DB', ['USER' => 'foo', 'PASS' => 'bar', 'HOST' => 'localhost', 'NAME' => 'baz', 'PORT' => 3306]);
PHP7
R.I.P
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 30 / 38
www.galvao.eti.br
<% %><script language=”php”>public function nome_da_classe()mysql_
Tudo o que você precisa saber sobre PHP7
R.I.P
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 31 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
<% %><script language=”php”>public function nome_da_classe()mysql_
R.I.P
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 32 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
DEFINITELY!
<% %><script language=”php”>public function nome_da_classe()mysql_
R.I.P
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 33 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
Oh God, YES!
<% %><script language=”php”>public function nome_da_classe()mysql_
R.I.P
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 34 / 38
www.galvao.eti.br
<% %><script language=”php”>public function nome_da_classe()mysql_
Tudo o que você precisa saber sobre PHP7
Ahn… well… kinda, yeah!
R.I.P
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 35 / 38
www.galvao.eti.br
<% %><script language=”php”>public function nome_da_classe()mysql_
Tudo o que você precisa saber sobre PHP7
Not really, but he HAS TO GO!
Já vão TARDE
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 36 / 38
www.galvao.eti.brTudo o que você precisa saber sobre PHP7
INFORME-SE!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 37 / 38
www.galvao.eti.br
PHP7: More strict! (but only if you want it to be), by myself!http://bit.ly/php7-more-strict
Referência, by Thomas Punthttps://github.com/tpunt/PHP7-Reference
PHP7 feature freeze, by Phil Sturgeonhttps://philsturgeon.uk/php/2015/03/15/php-7-feature-freeze/
An Exceptional Change in PHP 7.0, by Davey Shafikhttps://daveyshafik.com/archives/69237-an-exceptional-change-in-php-7-0.html
Tudo o que você precisa saber sobre PHP7
Muito obrigado!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 38 / 38
www.galvao.eti.br
? Dúvidas?↓ Críticas?↑ Elogios?!
Tudo o que você precisa saber sobre PHP7