O documento fornece uma introdução às principais novidades da versão PHP7, incluindo melhorias de desempenho, novos operadores e declarações de tipo, além de recursos removidos como o mysql_.
1. 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ê precisa
saber sobre
PHP7 Logo by Vincent Pontier, Freddie and other silly things by The Internet
2. Presidente da ABRAPHP – Associação Brasileira de Profissionais PHP
Diretor da PHP Conference Brasil
Contribui 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 internacionais
Instrutor de cursos presenciais e a distância
Fundador e líder do GU PHPBR
Fundador* e membro do GU PHPRS
Site: http://www.galvao.eti.br/
http://people.php.net/galvao
Twitter: @galvao
Slides e Documentos: http://slideshare.net/ergalvao
https://speakerdeck.com/galvao
Github: http://github.com/galvao
Posts: 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
3. 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 Operator
NULL Coalesce Operator
Group Use Declarations
Scalar Type Hints
Return Type Declarations
Exceptions in the engine
CSPRNG
Arrays Constantes
R.I.P.
mysql
Tags
Construtor estilo PHP4
Features
4. 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
5. 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?
6. 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?
7. 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
8. 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
9. 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
10. 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
*
12. CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 12 / 38
www.galvao.eti.br
1 <=> 0 → 1
P
ew
!
Tudo o que você precisa saber sobre PHP7
Spaceship Operator
13. CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 13 / 38
www.galvao.eti.br
1 <=> 0 → 1
1 <=> 1 → 0
P
ew
!
P
ew
!
Tudo o que você precisa saber sobre PHP7
Spaceship Operator
14. CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 10/9/15 - 14 / 38
www.galvao.eti.br
1 <=> 0 → 1
1 <=> 1 → 0
0 <=> 1 → -1 P
ew
!
P
ew
!
P
ew
!
Tudo o que você precisa saber sobre PHP7
Spaceship Operator
15. 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
16. 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 FooBar;
use FooBaz;
use FooQuux;
use Foo{Bar, Baz, Quux};
use Foo{
BarThud,
BazGruntBletch,
QuuxFum
};
17. 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
<?php
function foo(int $x, int $y)
{
return $x + $y;
}
echo foo('1', 2);
Coercive
Resultado: 3
18. 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
<?php
declare(strict_types=1);
function foo(int $x, int $y)
{
return $x + $y;
}
echo foo('1', 2);
Strict
19. 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
20. 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
21. 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
<?php
function foo($x,$y):int
{
return (string)($x + $y);
}
echo foo(1, 2);
Resultado: 3
Coercive
22. 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
<?php
declare(strict_types=1);
function foo($x,$y):int
{
return (string)($x + $y);
}
echo foo(1, 2);
Strict
23. 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
24. 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
25. 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());
}
26. 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
<?php
declare(strict_types=1);
function foo($x,$y):int
{
return (string)($x + $y);
}
try {
echo foo(1, 2);
} catch (TypeError $e) {
die($e->getMessage());
}
27. 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
28. 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
<?php
define('DB_USER', 'foo');
define('DB_PASS', 'bar');
define('DB_HOST', 'localhost');
define('DB_NAME', 'baz');
define('DB_PORT', 3306);
PHP5
29. 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
<?php
define('DB', ['USER' => 'foo',
'PASS' => 'bar',
'HOST' => 'localhost',
'NAME' => 'baz',
'PORT' => 3306]
);
PHP7
30. 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
31. 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_
32. 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_
33. 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_
34. 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!
35. 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!
36. 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
37. 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 Punt
https://github.com/tpunt/PHP7-Reference
PHP7 feature freeze, by Phil Sturgeon
https://philsturgeon.uk/php/2015/03/15/php-7-feature-freeze/
An Exceptional Change in PHP 7.0, by Davey Shafik
https://daveyshafik.com/archives/69237-an-exceptional-change-in-php-7-0.html
Tudo o que você precisa saber sobre PHP7
38. 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