Advertisement

Getting hands dirty with php7

Senior PHP architect & QA Specialist at In2IT
Feb. 12, 2016
Advertisement

More Related Content

Advertisement
Advertisement

Getting hands dirty with php7

  1. GETTING HANDS DIRTY
  2. MICHELANGELO VAN DAM PHP CONSULTANT & COMMUNITY LEADER Credits: phpbg on flickr.com
  3. AGENDA WHAT HAS CHANGED SINCE PHP 5? WHAT’S NEW IN PHP 7? OTHER THINGS YOU NEED TO KNOW MIGRATING PHP 5 APPS TO PHP 7 CLOSING REMARKS & QUESTIONS
  4. AGENDA WHAT HAS CHANGED SINCE PHP 5? WHAT’S NEW IN PHP 7? OTHER THINGS YOU NEED TO KNOW MIGRATING PHP 5 APPS TO PHP 7 CLOSING REMARKS & QUESTIONS
  5. BC BREAK CHANGED BEHAVIOR IN PHP 7 Source: Hernán Piñera on flickr.com
  6. FATAL ERRORS ๏ Fatal and recoverable fatal errors are now “Throwable” ๏ These errors inherit from “Error” class ๏ The “Errors” class is on the same level as ExcepFon class ๏ Both “Errors” and “ExcepFons” implement “Throwable” interface ๏ Has an effect on: ๏ “set_excepFon_handler”: can receive Errors and ExcepFons ๏ all internal classes now throw ExcepFon on construct failure ๏ Parse errors now throw “ParseError”
  7. EXAMPLE ERROR PHP 5 VS 7 <?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
  8. EXCEPTION HANDLING <?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}
  9. THROWABLE EXAMPLE <?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
  10. VARIABLE VARIABLES <?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
  11. 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!
  12. 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!
  13. LIST ORDER <?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
  14. FOREACH INTERNAL POINTER <?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)
  15. FOREACH ITERATION ISSUE <?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!
  16. INVALID OCTALS <?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
  17. NEGATIVE BITSHIFTS <?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
  18. BITSHIFT OVERFLOW <?php echo 'PHP ' . phpversion() . PHP_EOL; $a = 0b11111111111111111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111; 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
  19. DIVISION BY ZERO <?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
  20. HEX VALUES <?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"
  21. REMOVED FROM PHP 7 ๏ 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()
  22. REMOVED GD FUNCTIONS ๏ imagepsbbox() ๏ imagepsencodefont() ๏ imagepsextendfont() ๏ imagepsfreefont() ๏ imagepsloadfont() ๏ imagepsslanWont() ๏ imagepstext()
  23. EXT/MYSQL ๏ Deprecated in PHP 5.5 ๏ Removed in PHP 7 ๏ All mysql_* funcFons!!!
  24. WILL YOU MISS IT?!? ๏ script-tag
 <script language="php"> // PHP code goes here </script> ๏ ASP-tag
 <% // PHP code goes here %> <%= 'echoing something here' %>
  25. OTHER REMOVED/CHANGED ITEMS ๏ php.ini ๏ always_populate_raw_post_data ๏ asp_tags ๏ xsl.security_prefs ๏ $HTTP_RAW_POST_DATA -> php://input ๏ No # in INI files with parse_ini_file() or parse_ini_string() -> use ; ๏ func_get_arg() and func_get_args() return always current value of arguments (no longer original values)
  26. AGENDA WHAT HAS CHANGED SINCE PHP 5? WHAT’S NEW IN PHP 7? OTHER THINGS YOU NEED TO KNOW MIGRATING PHP 5 APPS TO PHP 7 CLOSING REMARKS & QUESTIONS
  27. PHP 7.1 - WHAT’S COMING
  28. NEW FEATURES…
  29. NULLABLE TYPE <?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);
  30. NULLABLE TYPE <?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);
  31. VOID FUNCTIONS <?php class Foo {     public function sayHello(string $message): void     {         echo 'Hello ' . $message . '!' . PHP_EOL;     } } $foo = new Foo(); $foo->sayHello('World');
  32. SYMMETRIC ARRAY DESTRUCTURING <?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; }
  33. SUPPORT FOR KEYS IN LIST() <?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;  }
  34. CLASS CONSTANT VISIBILITY <?php class ConstDemo {     const PUBLIC_CONST_A = 1;     public const PUBLIC_CONST_B = 2;     protected const PROTECTED_CONST = 3;     private const PRIVATE_CONST = 4; }
  35. ITERABLE PSEUDO-TYPE <?php function iterator(iterable $iterable) {     foreach ($iterable as $value) {         //     } }
  36. MULTI CATCH EXCEPTION HANDLING <?php try {     // some code } catch (FirstException | SecondException $e) {     // handle first and second exceptions }
  37. SUPPORT FOR NEGATIVE STRING OFFSETS <?php $string = 'ThisIsALongString.php'; echo substr($string, 0, strlen($string) - 4) . PHP_EOL; // Outputs: ThisIsALongString echo substr($string, 0, -4) . PHP_EOL; // Outputs: ThisIsALongString
  38. CONVERT CALLABLES TO CLOSURES WITH CLOSURE::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');
  39. ASYNCHRONOUS SIGNAL HANDLING <?php pcntl_async_signals(true); // turn on async signals pcntl_signal(SIGHUP,  function($sig) {     echo "SIGHUPn"; }); posix_kill(posix_getpid(), SIGHUP);
  40. HTTP/2 SERVER PUSH SUPPORT IN EXT/CURL ๏ CURLMOPT_PUSHFUNCTION ๏ CURL_PUSH_OK ๏ CURL_PUSH_DENY
  41. PHP 7.1: THE NEW STUFF
  42. NEW FUNCTIONS ๏ Closure ๏ Closure::fromCallable() ๏ CURL ๏ curl_mulF_errno() ๏ curl_share_errno() ๏ curl_share_strerror() ๏ SPL ๏ is_iterable() ๏ PCNTL ๏ pcntl_async_signals()
  43. NEW GLOBAL CONSTANTS ๏ Core Predefined Constants ๏ PHP_FD_SETSIZE ๏ CURL ๏ CURLMOPT_PUSHFUNCTION ๏ CURL_PUST_OK ๏ CURL_PUSH_DENY ๏ Data Filtering ๏ FILTER_FLAG_EMAIL_UNICODE ๏ JSON ๏ JSON_UNESCAPED_LINE_TERMINATORS
  44. NEW GLOBAL CONSTANTS (2) ๏ PostgreSQL ๏ PGSQL_NOTICE_LAST ๏ PGSQL_NOTICE_ALL ๏ PGSQL_NOTICE_CLEAR ๏ SPL ๏ MT_RAND_PHP
  45. NEW GLOBAL CONSTANTS (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
  46. BREAKING BC
  47. THESE MIGHT BREAK STUFF ๏ Throw on passing too few funcFon arguments ๏ Forbid dynamic calls to scope introspecFon funcFons ๏ Invalid class, interface, and trait names ๏ void ๏ iterable ๏ Numerical string conversions now respect scienFfic notaFon ๏ Fixes to mt_rand() algorithm ๏ rand() aliased to mt_rand() and srand() aliased to mt_srand() ๏ Disallow the ASCII delete control character (0x7F) in idenFfiers ๏ error_log changes with syslog error values
  48. THESE MIGHT BREAK STUFF (2) ๏ Do not call destructors on incomplete objects ๏ call_user_func() handling of reference arguments ๏ The empty index operator is not supported for strings anymore ๏ $str[] = $x throws a fatal error ๏ Removed ini direcFves ๏ session.entropy_file ๏ session.entropy_length ๏ session.hash_funcFon ๏ session.hash_bits_per_character
  49. DEPRECATED FEATURES
  50. THESE ARE NOW DEPRECATED ๏ ext/mcrypt ๏ Eval opFon for mb_ereg_replace() and mb_eregi_replace()
  51. CHANGED FUNCTIONS
  52. PHP CORE ๏ getopt() has an opFonal third parameter that exposes the index of the next element in the argument vector list to be processed. This is done via a by- ref parameter. ๏ getenv() no longer requires its parameter. If the parameter is omiTed, then the current environment variables will be returned as an associaFve array. ๏ get_headers() now has an addiFonal parameter to enable for the passing of custom stream contexts. ๏ long2ip() now also accepts an integer as a parameter. ๏ output_reset_rewrite_vars() no longer resets session URL rewrite variables. ๏ parse_url() is now more restricFve and supports RFC3986. ๏ unpack() now accepts an opFonal third parameter to specify the offset to begin unpacking from.
  53. OTHER CHANGED FUNCTIONS ๏ File System ๏ tempnam() now emits a noFce when falling back to the system's temp directory. ๏ JSON ๏ json_encode() now accepts a new opFon, JSON_UNESCAPED_LINE_TERMINATORS, to disable the escaping of U+2028 and U+2029 characters when JSON_UNESCAPED_UNICODE is supplied. ๏ MulTbyte String ๏ mb_ereg() now rejects illegal byte sequences. ๏ mb_ereg_replace() now rejects illegal byte sequences. ๏ PDO ๏ PDO::lastInsertId() for PostgreSQL will now trigger an error when nextval has not been called for the current session (the postgres connecFon).
  54. POSTGRESQL ๏ pg_last_noFce() now accepts an opFonal parameter to specify an operaFon. This can be done with one of the following new constants: PGSQL_NOTICE_LAST, PGSQL_NOTICE_ALL, or PGSQL_NOTICE_CLEAR. ๏ pg_fetch_all() now accepts an opFonal second parameter to specify the result type (similar to the third parameter of pg_fetch_array()). ๏ pg_select() now accepts an opFonal fourth parameter to specify the result type (similar to the third parameter of pg_fetch_array()).
  55. OTHER CHANGES
  56. OTHER CHANGES ๏ NoFces and warnings on arithmeFc with invalid strings ๏ New E_WARNING and E_NOTICE errors have been introduced when invalid strings are coerced using operators expecFng numbers ๏ E_NOTICE is emiTed when the string begins with a numeric value but contains trailing non-numeric characters ๏ E_WARNING is emiTed when the string does not contain a numeric value ๏ Warn on octal escape sequence overflow ๏ Inconsistency fixes to $this ๏ Session ID generaFon without hashing
  57. AGENDA WHAT HAS CHANGED SINCE PHP 5? WHAT’S NEW IN PHP 7? OTHER THINGS YOU NEED TO KNOW MIGRATING PHP 5 APPS TO PHP 7 CLOSING REMARKS & QUESTIONS
  58. OTHER THINGS THAT CHANGED ๏ FuncFon “set_excepFon_handler()” is no longer guaranteed to receive ExcepTon objects but Throwable objects ๏ Error reporFng E_STRICT noFces severity changes as some have been changed and will not trigger an error ๏ The deprecated “set_socket_blocking()” alias has been removed in favour of “stream_set_blocking()” ๏ Switch statements cannot have mulFple default blocks ๏ FuncFons cannot have mulFple parameters with the same name ๏ PHP funcFons “func_get_arg()” and “func_get_args()” now return current argument values
  59. PHP 7 PERFORMANCE
  60. PERFORMANCE WORDPRESS Source: Zend PHP 7 Infograph
  61. PERFORMANCE MAGENTO Source: Zend PHP 7 Infograph
  62. PERFORMANCE WORDPRESS Source: Zend PHP 7 Infograph
  63. PERFORMANCE FRAMEWORKS Source: Zend PHP 7 Infograph
  64. PERFORMANCE CRM Source: Zend PHP 7 Infograph
  65. PERFORMANCE COMPARISON TO OTHER LANGUAGES Source: Zend PHP 7 Infograph
  66. PERFORMANCE YII FRAMEWORK Source: caleblloyd.com
  67. AGENDA WHAT HAS CHANGED SINCE PHP 5? WHAT’S NEW IN PHP 7? OTHER THINGS YOU NEED TO KNOW MIGRATING PHP 5 APPS TO PHP 7 CLOSING REMARKS & QUESTIONS
  68. DOMAIN MODELS
  69. DOMAIN MODELS <?php namespace DragonBephp7workshop; 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;     } }
  70. DOMAIN MODELS (CONT.) <?php namespace DragonBephp7workshop; 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);     } }
  71. DOMAIN MODELS (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;     }
  72. DOMAIN MODELS (CONT.) <?php declare(strict_types=1); require_once __DIR__ . '/User.php'; use DragonBephp7workshopUser; $user = new User('michelangelo', '39'); var_dump($user);
  73. MYSQL EXTENSION
  74. S/MYSQL_/MYSQLI_ ๏ On bash you could grep -r mysql_ * in your project’s root directory to discover files sFll using old mysql elements ๏ Use your IDE and search for “mysql_” ๏ Most of the Fme you can just replace “mysql_” with “mysqli_”
  75. INCOMPATIBLE MYSQL_ FUNC. ๏ mysql_client_encoding() ๏ mysql_list_dbs() (use SHOW DATABASES query) ๏ mysql_db_name() ๏ mysql_list_fields() ๏ mysql_db_query() ๏ mysql_list_processes() (use SHOW PROCESSLIST query) ๏ mysql_dbname() ๏ mysql_list_tables() (use SHOW TABLES query) ๏ mysql_field_flags() ๏ mysql_listdbs() (use SHOW DATABASES query) ๏ mysql_field_len() ๏ mysql_lisWields() ๏ mysql_field_name() ๏ mysql_lisTables() (use SHOW TABLES query) ๏ mysql_field_table() ๏ mysql_numfields() ๏ mysql_field_type() ๏ mysql_numrows() (use mysqli_num_rows() instead) ๏ mysql_fieldflags() ๏ mysql_pconnect() (append p: to the hostname passed to mysqli_connect()) ๏ mysql_fieldlen() ๏ mysql_result() ๏ mysql_fieldname() ๏ mysql_selectdb() (use mysqli_select_db() instead) ๏ mysql_fieldtable() ๏ mysql_table_name() ๏ mysql_fieldtype() ๏ mysql_tablename() ๏ mysql_freeresult() (use mysqli_free_result() instead) ๏ mysql_unbuffered_query()
  76. USE PDO! PHP.NET/PDO
  77. AGENDA WHAT HAS CHANGED SINCE PHP 5? WHAT’S NEW IN PHP 7? OTHER THINGS YOU NEED TO KNOW MIGRATING PHP 5 APPS TO PHP 7 CLOSING REMARKS & QUESTIONS
  78. YOUR 1-STOP SOURCE PHP.NET/MANUAL/EN/MIGRATION70.PHP
  79. RECOMMENDED READING IN2.SE/PHP7BOOK
  80. PHP CHEATSHEETS PHPCHEATSHEETS.COM
  81. NOW READY FOR PHP 7 AND MORE COMING…
  82. YOUR PROJECTS… TIME TO UPGRADE
  83. in it2PROFESSIONAL PHP SERVICES Thank you! Slides at in2.se/hd-php7 training@in2it.be - www.in2it.be - T in2itvof - F in2itvof PHPUnit Getting Started Advanced Testing Zend Framework 2 Fundamentals Advanced Azure PHP Quick time to market Scale up and out jQuery Professional jQuery PHP PHP for beginners Professional PHP HTML & CSS The Basics Our training courses
  84. 29c51 If you enjoyed this talk, thanks. If not, tell me how to make it better Leave feedback and grab the slides
Advertisement