Top Banner
GETTING HANDS DIRTY
88

Getting hands dirty with php7

Jan 16, 2017

Download

Engineering

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting hands dirty with php7

GETTINGHANDSDIRTY

Page 2: Getting hands dirty with php7

MICHELANGELOVANDAMPHPCONSULTANT&COMMUNITYLEADER

Credits:phpbgonflickr.com

Page 3: Getting hands dirty with php7

AGENDAWHATHASCHANGEDSINCEPHP5?

WHAT’SNEWINPHP7?

OTHERTHINGSYOUNEEDTOKNOW

MIGRATINGPHP5APPSTOPHP7

CLOSINGREMARKS&QUESTIONS

Page 4: Getting hands dirty with php7

AGENDAWHATHASCHANGEDSINCEPHP5?

WHAT’SNEWINPHP7?

OTHERTHINGSYOUNEEDTOKNOW

MIGRATINGPHP5APPSTOPHP7

CLOSINGREMARKS&QUESTIONS

Page 5: Getting hands dirty with php7

BCBREAKCHANGEDBEHAVIORINPHP7

Source:HernánPiñeraonflickr.com

Page 6: Getting hands dirty with php7

FATALERRORS๏ Fatalandrecoverablefatalerrorsarenow“Throwable”

๏ Theseerrorsinheritfrom“Error”class

๏ The“Errors”classisonthesamelevelasExcepFonclass

๏ Both“Errors”and“ExcepFons”implement“Throwable”interface

๏ Hasaneffecton:

๏ “set_excepFon_handler”:canreceiveErrorsandExcepFons

๏ allinternalclassesnowthrowExcepFononconstructfailure

๏ Parseerrorsnowthrow“ParseError”

Page 7: Getting hands dirty with php7

EXAMPLEERRORPHP5VS7<?php

$example = new Example(); // PHP 5 error outputs: // PHP Fatal error:  Class 'Example' not found in php7-workshop/errors.php on line 4 // PHP Stack trace: // PHP   1. {main}() php7-workshop/errors.php:0

// PHP 7 error outputs: // PHP Fatal error:  Uncaught Error: Class 'Example' not found in php7-workshop/errors.php:4 // Stack trace: // #0 {main} //   thrown in php7-workshop/errors.php on line 4 // // Fatal error: Uncaught Error: Class 'Example' not found in php7-workshop/errors.php on line 4 // // Error: Class 'Example' not found in php7-workshop/errors.php on line 4 // // Call Stack: //    0.0003     351648   1. {main}() php7-workshop/errors.php:0

Page 8: Getting hands dirty with php7

EXCEPTIONHANDLING<?php

function exceptionHandler(Exception $e) {     echo 'PHP ' . phpversion() . PHP_EOL;     echo $e->getMessage() . PHP_EOL;     echo $e->getTraceAsString() . PHP_EOL; } set_exception_handler('exceptionHandler');

class Foo {     public function bar()     {         throw new Exception('foo-bar');     } }

$foo = new Foo(); $foo->bar();

// PHP 5.6.4 // foo-bar // #0 php7-workshop/Errors/errorhandler.php(24): Foo->bar() // #1 {main}

// PHP 7.0.2 // foo-bar // #0 php7-workshop/Errors/errorhandler.php(24): Foo->bar() // #1 {main}

Page 9: Getting hands dirty with php7

THROWABLEEXAMPLE<?php

echo 'PHP ' . phpversion() . PHP_EOL; try {     $foo = new foo(); } catch (Exception $e) {     echo 'I am an exception: ' . $e->getMessage() . PHP_EOL; } catch (Error $e) {     echo 'I am an error: ' . $e->getMessage() . PHP_EOL; } catch (Throwable $t) {     echo 'I am throwable: ' . $t->getMessage() . PHP_EOL; }

// PHP 5.6.4 // Fatal error: Class 'foo' not found in // php7-workshop/Errors/throwable.php on line 5

// PHP 7.0.2 // I am an error: Class 'foo' not found

Page 10: Getting hands dirty with php7

VARIABLEVARIABLES<?php

echo 'PHP ' . phpversion() . PHP_EOL; $foo = [     'bar' => [         'baz' => 'foo-bar-baz',         'bay' => 'foo-bar-bay',     ], ]; echo $foo['bar']['baz'] . PHP_EOL;

$foo = new \stdClass(); $foo->bar = ['baz' => 'foo-bar-baz']; $bar = 'bar'; echo $foo->$bar['baz'] . PHP_EOL;

// PHP 5.6.4 // foo-bar-baz // // Warning: Illegal string offset 'baz' in php7-workshop/Variable/vars.php on line 15

// PHP 7.0.2 // foo-bar-baz // foo-bar-baz

Page 11: Getting hands dirty with php7

GLOBALS<?php

echo 'PHP ' . phpversion() . PHP_EOL;

$a = 'Hello'; $$a = 'World!';

function foo() {     global $a, $$a;     return $a . ' ' . $$a; }

echo foo() . PHP_EOL;

// PHP 5.6.4 // Hello World!

// PHP 7.0.2 // Hello World!

Page 12: Getting hands dirty with php7

GLOBALS(CONT.)<?php

echo 'PHP ' . phpversion() . PHP_EOL;

$a = 'Hello'; $$a = 'World!';

function foo() {     global $a, ${$a};     return $a . ' ' . ${$a}; }

echo foo() . PHP_EOL;

// PHP 5.6.4 // Hello World!

// PHP 7.0.2 // Hello World!

Page 13: Getting hands dirty with php7

LISTORDER<?php

list ($a[], $a[], $a[]) = [1, 2, 3]; echo 'PHP ' . phpversion() . ': ' . implode(', ', $a) . PHP_EOL;

// PHP 5.6.4: 3, 2, 1 // PHP 7.0.2: 1, 2, 3

list ($b[], $b[], $b[]) = [3, 2, 1]; echo 'PHP ' . phpversion() . ': ' . implode(', ', $b) . PHP_EOL;

// PHP 5.6.4: 1, 2, 3 // PHP 7.0.2: 3, 2, 1

Page 14: Getting hands dirty with php7

FOREACHINTERNALPOINTER<?php

echo 'PHP ' . phpversion() . PHP_EOL; $a = [0, 1, 2]; foreach ($a as &$val) {     var_dump(current($a)); }

// PHP 5.6.4 // int(1) // int(2) // bool(false)

// PHP 7.0.2 // int(0) // int(0) // int(0)

Page 15: Getting hands dirty with php7

FOREACHITERATIONISSUE<?php

echo 'PHP ' . phpversion() . PHP_EOL; $a = ['a', 'b', 'c'];

foreach ($a as &$item) {     echo current($a) . PHP_EOL;     // When we reach the end, close with double newline     if (false === current($a)) {         echo PHP_EOL . PHP_EOL;     } }

echo 'Hello World!' . PHP_EOL;

// PHP 5.6.4 // b // c // // // // Hello World!

// PHP 7.0.2 // a // a // a // Hello World!

Page 16: Getting hands dirty with php7

INVALIDOCTALS<?php

echo 'PHP ' . phpversion() . PHP_EOL; $a = 0128; // faulty octal

var_dump($a);

// PHP 5.6.4 // int(10) -> PHP converted it to 012

// PHP 7.0.2 //  // Parse error: Invalid numeric literal in  //     php7-workshop/Octals/Octals.php on line 4

Page 17: Getting hands dirty with php7

NEGATIVEBITSHIFTS<?php

echo 'PHP ' . phpversion() . PHP_EOL; var_dump(1 >> -1);

// PHP 5.6.4 // int(0)

// PHP 7.0.2 // PHP Fatal error:  Uncaught ArithmeticError: Bit shift by //   negative number in php7-workshop/Bitshift/bitshift.php:4 // Stack trace: // #0 {main} //   thrown in php7-workshop/Bitshift/bitshift.php on line 4 //  // Fatal error: Uncaught ArithmeticError: Bit shift by negative //   number in php7-workshop/Bitshift/bitshift.php on line 4 //  // ArithmeticError: Bit shift by negative number in //   php7-workshop/Bitshift/bitshift.php on line 4 //  // Call Stack: //     0.0006     352104   1. {main}() php7-workshop/Bitshift/bitshift.php:0

Page 18: Getting hands dirty with php7

BITSHIFTOVERFLOW<?php echo 'PHP ' . phpversion() . PHP_EOL; $a = 0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; echo var_export($a >> 1, true) . PHP_EOL;

// PHP 5.3.29 // Parse error: syntax error, unexpected T_STRING in php7-workshop/Bitshift/outofrangebit.php on line 3

// PHP 5.6.4 // 0

// PHP 7.0.2 // 0

Page 19: Getting hands dirty with php7

DIVISIONBYZERO<?php

echo 'PHP ' . phpversion() . PHP_EOL;

echo (0 / 0) . PHP_EOL; echo (3 / 0) . PHP_EOL; echo (3 / 0) . PHP_EOL;

// PHP 5.6.4 // // Warning: Division by zero in php7-workshop/Zero/division.php on line 5 // Warning: Division by zero in php7-workshop/Zero/division.php on line 6 // Warning: Division by zero in php7-workshop/Zero/division.php on line 7

// PHP 7.0.2 // Warning: Division by zero in php7-workshop/Zero/division.php on line 5 // NAN // Warning: Division by zero in php7-workshop/Zero/division.php on line 6 // INF// Warning: Division by zero in php7-workshop/Zero/division.php on line 7 // INF

Page 20: Getting hands dirty with php7

HEXVALUES<?php

echo 'PHP ' . phpversion() . PHP_EOL;

var_dump("0x123" == "291"); var_dump(is_numeric("0x123")); var_dump("0xe" + "0x1"); var_dump(substr("foo", "0x1"));

// PHP 5.6.4 // bool(true) // bool(true) // int(15) // string(2) "oo"

// PHP 7.0.2 // bool(false) // bool(false) // int(0) // // Notice: A non well formed numeric value encountered // in php7-workshop/Hex/hex.php on line 8 // string(3) "foo"

Page 21: Getting hands dirty with php7

REMOVEDFROMPHP7๏ call_user_*

๏ call_user_method()->call_user_func()

๏ call_user_method_array()->call_user_func_array()

๏ mcrypt_*

๏ mcrypt_generic_end()->mcrypt_generic_deinit()

๏ mcrypt_ecb()->mcrypt_decrypt()

๏ mcrypt_cbc()->mcrypt_decrypt()

๏ mcrypt_cP()->mcrypt_decrypt()

๏ mcrypt_oP()->mcrypt_decrypt()

๏ datefmt_set_Fmezone_id()->datefmt_set_Fmezone()

๏ IntlDateFormaTer::setTimeZoneID()->IntlDateFormaTer::setTimeZone()

๏ set_magic_quotes_runFme()

๏ set_socket_blocking()->stream_set_blocking()

Page 22: Getting hands dirty with php7

REMOVEDGDFUNCTIONS๏ imagepsbbox()

๏ imagepsencodefont()

๏ imagepsextendfont()

๏ imagepsfreefont()

๏ imagepsloadfont()

๏ imagepsslanWont()

๏ imagepstext()

Page 23: Getting hands dirty with php7

EXT/MYSQL๏ DeprecatedinPHP5.5

๏ RemovedinPHP7

๏ Allmysql_*funcFons!!!

Page 24: Getting hands dirty with php7

WILLYOUMISSIT?!?๏ script-tag

<scriptlanguage="php">// PHP code goes here </script>

๏ ASP-tag<%// PHP code goes here %>

<%= 'echoing something here' %>

Page 25: Getting hands dirty with php7

OTHERREMOVED/CHANGEDITEMS๏ php.ini

๏ always_populate_raw_post_data

๏ asp_tags

๏ xsl.security_prefs

๏ $HTTP_RAW_POST_DATA->php://input

๏ No#inINIfileswithparse_ini_file()orparse_ini_string()->use;

๏ func_get_arg()andfunc_get_args()returnalwayscurrentvalueofarguments(nolongeroriginalvalues)

Page 26: Getting hands dirty with php7

AGENDAWHATHASCHANGEDSINCEPHP5?

WHAT’SNEWINPHP7?

OTHERTHINGSYOUNEEDTOKNOW

MIGRATINGPHP5APPSTOPHP7

CLOSINGREMARKS&QUESTIONS

Page 27: Getting hands dirty with php7
Page 28: Getting hands dirty with php7

PHP7.1-WHAT’SCOMING

Page 29: Getting hands dirty with php7

NEWFEATURES…

Page 30: Getting hands dirty with php7

NULLABLETYPE<?php

class Foo {     protected $bar;

    public function __construct(string $bar = null)     {          if (null !== $bar) {              $this->bar = $bar;          }     }

    public function getBar(): string     {         return $this->bar;     } }

$foo = new Foo(); $bar = $foo->getBar(); var_dump($bar);

Page 31: Getting hands dirty with php7
Page 32: Getting hands dirty with php7

NULLABLETYPE<?php

class Foo {     protected $bar;

    public function __construct(?string $bar = null)     {          if (null !== $bar) {              $this->bar = $bar;          }     }

    public function getBar(): ?string     {         return $this->bar;     } }

$foo = new Foo(); $bar = $foo->getBar(); var_dump($bar);

Page 33: Getting hands dirty with php7

VOIDFUNCTIONS<?php

class Foo {     public function sayHello(string $message): void     {         echo 'Hello ' . $message . '!' . PHP_EOL;     } }

$foo = new Foo(); $foo->sayHello('World');

Page 34: Getting hands dirty with php7

SYMMETRICARRAYDESTRUCTURING<?php

$talks = [     [1, 'Getting hands dirty with PHP7'],     [2, 'Decouple your framework'],     [3, 'PHPunit speedup with Docker'],     [4, 'Open source your business for success'], ];

// short-hand list notation [$id, $title] = $talks[0]; echo sprintf('%s (%d)', $title, $id) . PHP_EOL; echo PHP_EOL;

// shorthand foreach list notation foreach ($talks as [$id, $title]) {     echo sprintf('%s (%d)', $title, $id) . PHP_EOL; }

Page 35: Getting hands dirty with php7

SUPPORTFORKEYSINLIST()<?php 

$talks = [      [1, 'Getting hands dirty with PHP7'],      [2, 'Decouple your framework'],      [3, 'PHPunit speedup with Docker'],      [4, 'Open source your business for success'],  ]; 

// short-hand list notation  ['id' => $id, 'title' => $title] = $talks[0];  echo sprintf('%s (%d)', $title, $id) . PHP_EOL;  echo PHP_EOL; 

// shorthand foreach list notation  foreach ($talks as ['id' => $id, 'title' => $title]) {      echo sprintf('%s (%d)', $title, $id) . PHP_EOL;  }

Page 36: Getting hands dirty with php7

CLASSCONSTANTVISIBILITY<?php

class ConstDemo {     const PUBLIC_CONST_A = 1;     public const PUBLIC_CONST_B = 2;     protected const PROTECTED_CONST = 3;     private const PRIVATE_CONST = 4; }

Page 37: Getting hands dirty with php7

ITERABLEPSEUDO-TYPE<?php function iterator(iterable $iterable) {     foreach ($iterable as $value) {         //     } }

Page 38: Getting hands dirty with php7

MULTICATCHEXCEPTIONHANDLING<?php try {     // some code } catch (FirstException | SecondException $e) {     // handle first and second exceptions }

Page 39: Getting hands dirty with php7

SUPPORTFORNEGATIVESTRINGOFFSETS<?php

$string = 'ThisIsALongString.php'; echo substr($string, 0, strlen($string) - 4) . PHP_EOL; // Outputs: ThisIsALongString

echo substr($string, 0, -4) . PHP_EOL; // Outputs: ThisIsALongString

Page 40: Getting hands dirty with php7

CONVERTCALLABLESTOCLOSURESWITHCLOSURE::FROMCALLABLE()<?php class Test {     public function exposeFunction()     {         return Closure::fromCallable([$this, 'privateFunction']);     }

    private function privateFunction($param)     {         var_dump($param);     } }

$privFunc = (new Test)->exposeFunction(); $privFunc('some value');

Page 41: Getting hands dirty with php7

ASYNCHRONOUSSIGNALHANDLING<?php pcntl_async_signals(true); // turn on async signals

pcntl_signal(SIGHUP,  function($sig) {     echo "SIGHUP\n"; });

posix_kill(posix_getpid(), SIGHUP);

Page 42: Getting hands dirty with php7

HTTP/2SERVERPUSHSUPPORTINEXT/CURL๏ CURLMOPT_PUSHFUNCTION

๏ CURL_PUSH_OK

๏ CURL_PUSH_DENY

Page 43: Getting hands dirty with php7

PHP7.1:THENEWSTUFF

Page 44: Getting hands dirty with php7

NEWFUNCTIONS๏ Closure

๏ Closure::fromCallable()

๏ CURL

๏ curl_mulF_errno()

๏ curl_share_errno()

๏ curl_share_strerror()

๏ SPL

๏ is_iterable()

๏ PCNTL

๏ pcntl_async_signals()

Page 45: Getting hands dirty with php7

NEWGLOBALCONSTANTS๏ CorePredefinedConstants

๏ PHP_FD_SETSIZE

๏ CURL

๏ CURLMOPT_PUSHFUNCTION

๏ CURL_PUST_OK

๏ CURL_PUSH_DENY

๏ DataFiltering

๏ FILTER_FLAG_EMAIL_UNICODE

๏ JSON

๏ JSON_UNESCAPED_LINE_TERMINATORS

Page 46: Getting hands dirty with php7

NEWGLOBALCONSTANTS(2)๏ PostgreSQL

๏ PGSQL_NOTICE_LAST

๏ PGSQL_NOTICE_ALL

๏ PGSQL_NOTICE_CLEAR

๏ SPL

๏ MT_RAND_PHP

Page 47: Getting hands dirty with php7

NEWGLOBALCONSTANTS(3)๏ LDAP_OPT_X_SASL_NOCANON

๏ LDAP_OPT_X_SASL_USERNAME

๏ LDAP_OPT_X_TLS_CACERTDIR

๏ LDAP_OPT_X_TLS_CACERTFILE

๏ LDAP_OPT_X_TLS_CERTFILE

๏ LDAP_OPT_X_TLS_CIPHER_SUITE

๏ LDAP_OPT_X_TLS_KEYFILE

๏ LDAP_OPT_X_TLS_RANDOM_FILE

๏ LDAP_OPT_X_TLS_CRLCHECK

๏ LDAP_OPT_X_TLS_CRL_NONE

๏ LDAP_OPT_X_TLS_CRL_PEER

๏ LDAP_OPT_X_TLS_CRL_ALL

๏ LDAP_OPT_X_TLS_DHFILE

๏ LDAP_OPT_X_TLS_CRLFILE

๏ LDAP_OPT_X_TLS_PROTOCOL_MIN

๏ LDAP_OPT_X_TLS_PROTOCOL_SSL2

๏ LDAP_OPT_X_TLS_PROTOCOL_SSL3

๏ LDAP_OPT_X_TLS_PROTOCOL_TLS1_0

๏ LDAP_OPT_X_TLS_PROTOCOL_TLS1_1

๏ LDAP_OPT_X_TLS_PROTOCOL_TLS1_2

๏ LDAP_OPT_X_TLS_PACKAGE

๏ LDAP_OPT_X_KEEPALIVE_IDLE

๏ LDAP_OPT_X_KEEPALIVE_PROBES

๏ LDAP_OPT_X_KEEPALIVE_INTERVAL

Page 48: Getting hands dirty with php7

BREAKINGBC

Page 49: Getting hands dirty with php7

THESEMIGHTBREAKSTUFF๏ ThrowonpassingtoofewfuncFonarguments

๏ ForbiddynamiccallstoscopeintrospecFonfuncFons

๏ Invalidclass,interface,andtraitnames

๏ void

๏ iterable

๏ NumericalstringconversionsnowrespectscienFficnotaFon

๏ Fixestomt_rand()algorithm

๏ rand()aliasedtomt_rand()andsrand()aliasedtomt_srand()

๏ DisallowtheASCIIdeletecontrolcharacter(0x7F)inidenFfiers

๏ error_logchangeswithsyslogerrorvalues

Page 50: Getting hands dirty with php7

THESEMIGHTBREAKSTUFF(2)๏ Donotcalldestructorsonincompleteobjects

๏ call_user_func()handlingofreferencearguments

๏ Theemptyindexoperatorisnotsupportedforstringsanymore

๏ $str[]=$xthrowsafatalerror

๏ RemovedinidirecFves

๏ session.entropy_file

๏ session.entropy_length

๏ session.hash_funcFon

๏ session.hash_bits_per_character

Page 51: Getting hands dirty with php7

DEPRECATEDFEATURES

Page 52: Getting hands dirty with php7

THESEARENOWDEPRECATED๏ ext/mcrypt

๏ EvalopFonformb_ereg_replace()andmb_eregi_replace()

Page 53: Getting hands dirty with php7

CHANGEDFUNCTIONS

Page 54: Getting hands dirty with php7

PHPCORE๏ getopt()hasanopFonalthirdparameterthatexposestheindexofthenextelementintheargumentvectorlisttobeprocessed.Thisisdoneviaaby-refparameter.

๏ getenv()nolongerrequiresitsparameter.IftheparameterisomiTed,thenthecurrentenvironmentvariableswillbereturnedasanassociaFvearray.

๏ get_headers()nowhasanaddiFonalparametertoenableforthepassingofcustomstreamcontexts.

๏ long2ip()nowalsoacceptsanintegerasaparameter.

๏ output_reset_rewrite_vars()nolongerresetssessionURLrewritevariables.

๏ parse_url()isnowmorerestricFveandsupportsRFC3986.

๏ unpack()nowacceptsanopFonalthirdparametertospecifytheoffsettobeginunpackingfrom.

Page 55: Getting hands dirty with php7

OTHERCHANGEDFUNCTIONS๏ FileSystem

๏ tempnam()nowemitsanoFcewhenfallingbacktothesystem'stempdirectory.

๏ JSON

๏ json_encode()nowacceptsanewopFon,JSON_UNESCAPED_LINE_TERMINATORS,todisabletheescapingofU+2028andU+2029characterswhenJSON_UNESCAPED_UNICODEissupplied.

๏ MulTbyteString

๏ mb_ereg()nowrejectsillegalbytesequences.

๏ mb_ereg_replace()nowrejectsillegalbytesequences.

๏ PDO

๏ PDO::lastInsertId()forPostgreSQLwillnowtriggeranerrorwhennextvalhasnotbeencalledforthecurrentsession(thepostgresconnecFon).

Page 56: Getting hands dirty with php7

POSTGRESQL๏ pg_last_noFce()nowacceptsanopFonalparametertospecifyanoperaFon.Thiscanbedonewithoneofthefollowingnewconstants:PGSQL_NOTICE_LAST,PGSQL_NOTICE_ALL,orPGSQL_NOTICE_CLEAR.

๏ pg_fetch_all()nowacceptsanopFonalsecondparametertospecifytheresulttype(similartothethirdparameterofpg_fetch_array()).

๏ pg_select()nowacceptsanopFonalfourthparametertospecifytheresulttype(similartothethirdparameterofpg_fetch_array()).

Page 57: Getting hands dirty with php7

OTHERCHANGES

Page 58: Getting hands dirty with php7

OTHERCHANGES๏ NoFcesandwarningsonarithmeFcwithinvalidstrings

๏ NewE_WARNINGandE_NOTICEerrorshavebeenintroducedwheninvalidstringsarecoercedusingoperatorsexpecFngnumbers

๏ E_NOTICEisemiTedwhenthestringbeginswithanumericvaluebutcontainstrailingnon-numericcharacters

๏ E_WARNINGisemiTedwhenthestringdoesnotcontainanumericvalue

๏ Warnonoctalescapesequenceoverflow

๏ Inconsistencyfixesto$this

๏ SessionIDgeneraFonwithouthashing

Page 59: Getting hands dirty with php7

AGENDAWHATHASCHANGEDSINCEPHP5?

WHAT’SNEWINPHP7?

OTHERTHINGSYOUNEEDTOKNOW

MIGRATINGPHP5APPSTOPHP7

CLOSINGREMARKS&QUESTIONS

Page 60: Getting hands dirty with php7

OTHERTHINGSTHATCHANGED๏ FuncFon“set_excepFon_handler()”isnolongerguaranteedtoreceiveExcepTonobjectsbutThrowableobjects

๏ ErrorreporFngE_STRICTnoFcesseveritychangesassomehavebeenchangedandwillnottriggeranerror

๏ Thedeprecated“set_socket_blocking()”aliashasbeenremovedinfavourof“stream_set_blocking()”

๏ SwitchstatementscannothavemulFpledefaultblocks

๏ FuncFonscannothavemulFpleparameterswiththesamename

๏ PHPfuncFons“func_get_arg()”and“func_get_args()”nowreturncurrentargumentvalues

Page 61: Getting hands dirty with php7

PHP7PERFORMANCE

Page 62: Getting hands dirty with php7

PERFORMANCEWORDPRESS

Source:ZendPHP7Infograph

Page 63: Getting hands dirty with php7

PERFORMANCEMAGENTO

Source:ZendPHP7Infograph

Page 64: Getting hands dirty with php7

PERFORMANCEWORDPRESS

Source:ZendPHP7Infograph

Page 65: Getting hands dirty with php7

PERFORMANCEFRAMEWORKS

Source:ZendPHP7Infograph

Page 66: Getting hands dirty with php7

PERFORMANCECRM

Source:ZendPHP7Infograph

Page 67: Getting hands dirty with php7

PERFORMANCECOMPARISONTOOTHERLANGUAGES

Source:ZendPHP7Infograph

Page 68: Getting hands dirty with php7

PERFORMANCEYIIFRAMEWORK

Source:caleblloyd.com

Page 69: Getting hands dirty with php7

AGENDAWHATHASCHANGEDSINCEPHP5?

WHAT’SNEWINPHP7?

OTHERTHINGSYOUNEEDTOKNOW

MIGRATINGPHP5APPSTOPHP7

CLOSINGREMARKS&QUESTIONS

Page 70: Getting hands dirty with php7

DOMAINMODELS

Page 71: Getting hands dirty with php7

DOMAINMODELS<?php namespace DragonBe\php7workshop;

class User {     /** @var string $name The Name of the User */     protected $name;     /** @var int $age The age of the User */     protected $age;

    /**      * User constructor.      *      * @param string $name The name of the User      * @param int $age The age of the User      */     public function __construct($name = '', $age = 0)     {         $this->setName($name)             ->setAge($age);     }

    /**      * Sets the name of the User      *      * @param string $name The name of the User      * @return User      */     public function setName($name)     {         $this->name = (string) $name;         return $this;     }

    /**      * Retrieve the name of the User      *      * @return string      */     public function getName()     {         return $this->name;     }

    /**      * Sets the age of the User      *      * @param int $age      * @return User      */     public function setAge($age)     {         $this->age = (int) $age;         return $this;     }

    /**      * Retrieve the age of the User      * @return int      */     public function getAge()     {         return $this->age;     } }

Page 72: Getting hands dirty with php7

DOMAINMODELS(CONT.)<?php namespace DragonBe\php7workshop;

class User {     /** @var string $name The Name of the User */     protected $name;     /** @var int $age The age of the User */     protected $age;

    /**      * User constructor.      *      * @param string $name The name of the User      * @param int $age The age of the User      * @throws \TypeError      */     public function __construct(string $name = '', int $age = 0)     {         $this->setName($name)             ->setAge($age);     } }

Page 73: Getting hands dirty with php7

DOMAINMODELS(CONT.)    /**      * Sets the name of the User      *      * @param string $name The name of the User      * @return User      */     public function setName(string $name): User     {         $this->name = $name;         return $this;     }

    /**      * Retrieve the name of the User      *      * @return string      */     public function getName(): string     {         return $this->name;     }

    /**      * Sets the age of the User      *      * @param int $age      * @return User      */     public function setAge(int $age): User     {         $this->age = $age;         return $this;     }

    /**      * Retrieve the age of the User      * @return int      */     public function getAge(): int     {         return $this->age;     }

Page 74: Getting hands dirty with php7

DOMAINMODELS(CONT.)<?php declare(strict_types=1);

require_once __DIR__ . '/User.php';

use \DragonBe\php7workshop\User;

$user = new User('michelangelo', '39'); var_dump($user);

Page 75: Getting hands dirty with php7
Page 76: Getting hands dirty with php7

MYSQLEXTENSION

Page 77: Getting hands dirty with php7

S/MYSQL_/MYSQLI_๏ Onbashyoucouldgrep -r mysql_ *inyourproject’srootdirectorytodiscoverfilessFllusingoldmysqlelements

๏ UseyourIDEandsearchfor“mysql_”

๏ MostoftheFmeyoucanjustreplace“mysql_”with“mysqli_”

Page 78: Getting hands dirty with php7

INCOMPATIBLEMYSQL_FUNC.๏ mysql_client_encoding()

๏ mysql_list_dbs()(useSHOWDATABASESquery)

๏ mysql_db_name()

๏ mysql_list_fields()

๏ mysql_db_query()

๏ mysql_list_processes()(useSHOWPROCESSLISTquery)

๏ mysql_dbname()

๏ mysql_list_tables()(useSHOWTABLESquery)

๏ mysql_field_flags()

๏ mysql_listdbs()(useSHOWDATABASESquery)

๏ mysql_field_len()

๏ mysql_lisWields()

๏ mysql_field_name()

๏ mysql_lisTables()(useSHOWTABLESquery)

๏ mysql_field_table()

๏ mysql_numfields()

๏ mysql_field_type()

๏ mysql_numrows()(usemysqli_num_rows()instead)

๏ mysql_fieldflags()

๏ mysql_pconnect()(appendp:tothehostnamepassedtomysqli_connect())

๏ mysql_fieldlen()

๏ mysql_result()๏ mysql_fieldname()

๏ mysql_selectdb()(usemysqli_select_db()instead)

๏ mysql_fieldtable()

๏ mysql_table_name()

๏ mysql_fieldtype()

๏ mysql_tablename()

๏ mysql_freeresult()(usemysqli_free_result()instead)

๏ mysql_unbuffered_query()

Page 79: Getting hands dirty with php7

USEPDO!PHP.NET/PDO

Page 80: Getting hands dirty with php7

AGENDAWHATHASCHANGEDSINCEPHP5?

WHAT’SNEWINPHP7?

OTHERTHINGSYOUNEEDTOKNOW

MIGRATINGPHP5APPSTOPHP7

CLOSINGREMARKS&QUESTIONS

Page 81: Getting hands dirty with php7

YOUR1-STOPSOURCEPHP.NET/MANUAL/EN/MIGRATION70.PHP

Page 82: Getting hands dirty with php7

RECOMMENDEDREADINGIN2.SE/PHP7BOOK

Page 83: Getting hands dirty with php7

PHPCHEATSHEETSPHPCHEATSHEETS.COM

Page 84: Getting hands dirty with php7

NOWREADYFORPHP7ANDMORECOMING…

Page 85: Getting hands dirty with php7

YOURPROJECTS…TIMETOUPGRADE

Page 86: Getting hands dirty with php7

in it2PROFESSIONAL PHP SERVICES

Thank you!Slides at in2.se/hd-php7

[email protected] - www.in2it.be - T in2itvof - F in2itvof

PHPUnit

Getting StartedAdvanced Testing

Zend Framework 2

FundamentalsAdvanced

Azure PHP

Quick time to marketScale up and out

jQuery

Professional jQuery

PHP

PHP for beginnersProfessional PHP

HTML & CSS

The Basics

Our training courses

Page 87: Getting hands dirty with php7

29c51

If you enjoyed this talk, thanks. If not, tell me how to make it better

Leave feedback and grab the slides

Page 88: Getting hands dirty with php7