Slide 1

Slide 1 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 1 / 40 Top 10 Features do PHP Moderno www.galvao.eti.br TOP 10 Features do php Moderno

Slide 2

Slide 2 text

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. Professor Convidado de Pós-Graduação, PR e SC. 22+ anos desenvolvendo sistemas e aplicações com interface web 17+ destes com PHP 9+ com Zend Framework Palestrante em eventos nacionais e internacionais Instrutor de cursos presenciais e a distância Fundador* e membro do GU PHPRS Site: https://www.galvao.eti.br/ http://people.php.net/galvao Twitter: @galvao Facebook: https://www.facebook.com/galvao.eti.br/ 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 - 5/31/17 - 2 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno

Slide 3

Slide 3 text

Objetivo CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 3 / 40 www.galvao.eti.br → Atualizar quem já trabalha com a linguagem; → Eliminar um pouco do estigma que a linguagem possui; → Demonstrar o poder que a linguagem possui atualmente; Top 10 Features do PHP Moderno

Slide 4

Slide 4 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 4 / 40 www.galvao.eti.br 1. Namespaces PHP 5.3 ≃ 8 anos Top 10 Features do PHP Moderno

Slide 5

Slide 5 text

Namespaces CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 5 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno

Slide 6

Slide 6 text

Namespaces CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 6 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno código função objeto namespace

Slide 7

Slide 7 text

Namespaces CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 7 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno namespaces autoloader composer packagist { "require": { "guzzlehttp/guzzle": "^6.2", "phpmailer/phpmailer": "^5.2" } }

Slide 8

Slide 8 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 8 / 40 www.galvao.eti.br 2. STH / RTD / Strict Types PHP 7.0 / 7.1 / ... ≃ 1.5 ano Top 10 Features do PHP Moderno

Slide 9

Slide 9 text

STH / RTD / Strict Types CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 9 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno

Slide 10

Slide 10 text

void* > Strict Types CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 10 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno

Slide 11

Slide 11 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 11 / 40 www.galvao.eti.br 3. Funções Anônimas Top 10 Features do PHP Moderno PHP 5.3 ≃ 8 anos

Slide 12

Slide 12 text

Funções Anônimas CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 12 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno

Slide 13

Slide 13 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 13 / 40 www.galvao.eti.br 4. Hash de senhas Top 10 Features do PHP Moderno PHP 5.5 ≃ 4 anos

Slide 14

Slide 14 text

password_hash CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 14 / 40 www.galvao.eti.br Os 4 Pilares de Segurança de uma Aplicação $senha = password_hash($plain, PASSWORD_ DEFAULT BCRYPT [, $options]); hash_resultante dado original algo salt opções

Slide 15

Slide 15 text

password_hash CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 15 / 40 www.galvao.eti.br Os 4 Pilares de Segurança de uma Aplicação password_hash password_verify password_needs_rehash

Slide 16

Slide 16 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 16 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno PASSWORD_DEFAULT, 'options' => [ 'cost' => 10, ], ]; $inputPass = 'mypass'; $pass = password_hash($inputPass, $crypto['algo'], $crypto['options']); if (password_verify($inputPass, $pass)) { $crypto['options']['cost'] = 12; if (password_needs_rehash($inputPass, $crypto['algo'], $crypto['options'])) { $newPass = password_hash($inputPass, $crypto['algo'], $crypto['options']); } } password_hash

Slide 17

Slide 17 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 17 / 40 www.galvao.eti.br 5. Filtragem e Validação Top 10 Features do PHP Moderno PHP 5.2 ≃ 11 anos

Slide 18

Slide 18 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 18 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Filtragem e Validação filter_var($dado, FILTER_ SANITIZE_ VALIDATE_ EMAIL ENCODED MAGIC_QUOTES NUMBER_FLOAT NUMBER_INT SPECIAL_CHARS FULL_SPECIAL_CHARS STRING STRIPPED URL UNSAFE_RAW BOOLEAN EMAIL FLOAT INT IP MAC REGEXP URL ); CALLBACK

Slide 19

Slide 19 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 19 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno function ($dado) { return preg_replace('/[^\d|\-|\.]/', '', $dado); }] ); if (!filter_var($telefone, FILTER_VALIDATE_REGEXP, [ 'options' => [ 'regexp' => '/[\d|\-|\.]/' ] ])) { die('Telefone inválido'); } Filtragem e Validação

Slide 20

Slide 20 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 20 / 40 www.galvao.eti.br 6. Criptografia Top 10 Features do PHP Moderno PHP 5 ≃ 12 anos

Slide 21

Slide 21 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 21 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Criptografia openssl_ encrypt decrypt ($dado, method, key, options, IV); cifra + modo

Slide 22

Slide 22 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 22 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno 'aes-256-ctr', 'KEY' => '46f9cae861ec7c5474102c0a901b7a44', 'IV' => '35e59367dc417e703757341520d1486d', ]); $crypt = openssl_encrypt($data, CRYPTO['CIPHER'], CRYPTO['KEY'], 0, CRYPTO['IV'] ); $decrypt = openssl_decrypt($crypt, CRYPTO['CIPHER'], CRYPTO['KEY'], 0, CRYPTO['IV'] ); Criptografia

Slide 23

Slide 23 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 23 / 40 www.galvao.eti.br 7. CSPRNG Top 10 Features do PHP Moderno PHP 4/7* ≃17 anos / ≃ 1.5 ano

Slide 24

Slide 24 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 24 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno = 4 $randomInt = mt_rand(0, 2); // $randomStr = Alguma implementação customizada

Slide 25

Slide 25 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 25 / 40 www.galvao.eti.br 8. Traits Top 10 Features do PHP Moderno PHP 5.4 ≃ 5 anos

Slide 26

Slide 26 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 26 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno

Slide 27

Slide 27 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 27 / 40 www.galvao.eti.br 9. Generators Top 10 Features do PHP Moderno PHP 5.5 ≃ 4 anos

Slide 28

Slide 28 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 28 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno diff($end); echo 'O array $array contém ' . number_format(count($array)) . “ elementos.\n”; echo $interval->format('%S segundos.') . “\n”; Generators O array $array contém 1,000,001 elementos. 00 segundos.

Slide 29

Slide 29 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 29 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno diff($end); echo 'O array $array contém ' . number_format(count($array)) . “ elementos.\n”; echo $interval->format('%S segundos.') . “\n”; Generators Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 536870920 bytes) in /var/www/.../g1.php on line 6 536 Mb – Memória excedida em 402 Mb

Slide 30

Slide 30 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 30 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno diff($end); echo 'O array $array contém ' . number_format(count($array)) . “ elementos.\n”; echo $interval->format('%S segundos.') . “\n”; Generators Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 134217736 bytes) in /var/www/.../g1.php on line 6 134 Mb : Memória excedida em 8 bytes

Slide 31

Slide 31 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 31 / 40 www.galvao.eti.br 10. Abstração de BD Top 10 Features do PHP Moderno PHP 5* ≃ 12 anos

Slide 32

Slide 32 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 32 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno 'mysql', 'HOST' => 'localhost', 'PORT' => 3306, 'NAME' => 'teste', 'USER' => 'aluno', 'PASS' => 'aluno', ]); $dsn = DB['DRIVER'] . ':host=' . DB['HOST'] . ';port=' . DB['PORT'] . ';dbname=' . DB['NAME']; $dbh = new PDO($dsn, DB['USER'], DB['PASS']); $sql = "INSERT into foo (bar) VALUES ('baz')"; $dbh->exec($sql); $dbh = NULL; PDO

Slide 33

Slide 33 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 33 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno 'pgsql', 'HOST' => 'localhost', 'PORT' => 5432, 'NAME' => 'teste', 'USER' => 'aluno', 'PASS' => 'aluno', ]); $dsn = DB['DRIVER'] . ':host=' . DB['HOST'] . ';port=' . DB['PORT'] . ';dbname=' . DB['NAME'] . ‘;user=’ . DB[‘USER’] . ‘;password=’ . DB[‘PASS’]; $dbh = new PDO($dsn); $sql = "INSERT into foo (bar) VALUES ('baz')"; $dbh->exec($sql); $dbh = NULL; PDO

Slide 34

Slide 34 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 34 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno MS SQL Server Sybase Firebird IBM DB2 IBM Informix Oracle ODBC SQLite ... PDO++

Slide 35

Slide 35 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 35 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Concluindo...

Slide 36

Slide 36 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 36 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Concluindo… R

Slide 37

Slide 37 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 37 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Concluindo… RT

Slide 38

Slide 38 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 38 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Concluindo… RTF

Slide 39

Slide 39 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 39 / 40 www.galvao.eti.br Top 10 Features do PHP Moderno Concluindo… RTFM!!! Concluindo… RTFM!!! http://php.net/manual/en/index.php Concluindo… RTFM!!! Concluindo… RTFM!!!

Slide 40

Slide 40 text

Muito obrigado! CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/31/17 - 40 / 40 www.galvao.eti.br ? Dúvidas? ↓ Críticas? ↑ Elogios?! Top 10 Features do PHP Moderno