PHP 7 - Think php7
-
Upload
christophe-villeneuve -
Category
Internet
-
view
891 -
download
0
Transcript of PHP 7 - Think php7
![Page 1: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/1.jpg)
nAcademy Le 26 février 2015 Neuros
PHP 7
Think php7
Christophe Villeneuve
![Page 2: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/2.jpg)
nAcademy Le 26 février 2015 Neuros
Aujourd'hui...● Situation actuelle● Le futur● PHP 7
Thank's Rasmus Lerdorf
2015 20 ans PHP
![Page 3: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/3.jpg)
nAcademy Le 26 février 2015 Neuros
Qui... est Christophe Villeneuve ?
<<
![Page 4: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/4.jpg)
nAcademy Le 26 février 2015 Neuros
Situation actuellePicture hellosct1 : Pyramide elePHPant
![Page 5: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/5.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 5.2 ✔ The END 2010
PHP (1/6)
![Page 6: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/6.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 5.2➢PHP 5.3
✔ De 2009 à Août 2014
✔ ChangeLog
✔ Namespace✔ Etc.
PHP (2/6)
![Page 7: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/7.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 5.2➢PHP 5.3➢PHP 5.4
✔Dispo Mars 2012
✔ChangeLog
✔ Les traits✔ Etc.
PHP (3/6)
![Page 8: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/8.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 5.2➢PHP 5.3➢PHP 5.4➢PHP 5.5
✔ Dispo juin 2013
✔ ChangeLog
✔ Générators✔ OpCache✔ Principalement la sécurité
PHP (4/6)
![Page 9: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/9.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 6.0
✔ No Comment
Screen Hidden
![Page 10: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/10.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 5.2➢PHP 5.3➢PHP 5.4➢PHP 5.5➢PHP 5.6
✔ Dispo Août 2014
✔ Variadics
✔ Function fn ($id,$params);✔ Splat Operator
✔ Function test (arg1, arg2=null)✔ Operator
✔ echo 2 xx 3 ; // 8✔ Nice speed bump
✔ Etc.
PHP (5/6)
![Page 11: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/11.jpg)
nAcademy Le 26 février 2015 Neuros
➢PHP 5.2➢PHP 5.3➢PHP 5.4➢PHP 5.5➢PHP 5.6
✔ Dispo Septembre 2015
✔ Next changeLog
✔ ...
➢PHP 5.7
PHP (6/6)
![Page 12: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/12.jpg)
nAcademy Le 26 février 2015 Neuros
+ =
5 + 1 = 7
![Page 13: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/13.jpg)
nAcademy Le 26 février 2015 Neuros
PHP Alternative Implementations
Source : https://wiki.php.net/rfc/php7_57_roadmap
● PHP 7– PHP Next Generation (PHPNG)
● HHVM– Code natif
● Reckict– Code natif
● Phalanger– .net engine
![Page 14: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/14.jpg)
nAcademy Le 26 février 2015 Neuros
Roadmap
Source : https://wiki.php.net/rfc/php7_57_roadmap
![Page 15: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/15.jpg)
nAcademy Le 26 février 2015 Neuros
Les changements
? yes
A whale(Une baleine)
Picture hellosct1 : Tadoussac 2011 – elePHPant VS whale
![Page 16: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/16.jpg)
nAcademy Le 26 février 2015 Neuros
Features● :D
– PHP Next Generation
– Modification structure données
– Nouvelle gestion de mémoire
– Etc
● :( – Ext/MySQL
– Ext/ereg
– ASP Style Tags<% ou <%= et %>
– Etc.
:( Source : https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7
![Page 17: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/17.jpg)
nAcademy Le 26 février 2015 Neuros
● Structure intermédiaire dans le process de compilation
→ gain de performance et au niveau mémoire● Améliore la qualité du code● Position avant OpCode
<?php
//aucun
Source : https://wiki.php.net/rfc/abstract_syntax_tree
Abstract syntax tree
![Page 18: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/18.jpg)
nAcademy Le 26 février 2015 Neuros
Null Coalesce Operator● Modifie le comportement de l'opérateur ?
→ fonction isset() en automatique
● Disponible – Dans une chaîne
– Dans un appel de méthode / fonction
<?php
//Avant
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
//PHP 7.0
$username = $_GET['user'] ?? 'nobody';
Source : https://wiki.php.net/rfc/isset_ternary
![Page 19: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/19.jpg)
nAcademy Le 26 février 2015 Neuros
Unicode Codepoint Escape Syntax● Utilisation de séquences Unicode dans les chaînes
de caractères● { et } code de caractères ←
lisibilité + pas de limite au nombre de caractères
Source : https://wiki.php.net/rfc/unicode_escape
<?php
echo "\u{202E}Reversed text"; // outputs Reversed text
echo "ma\u{00F1}ana"; // pre-composed character ñ
echo "man\u{0303}ana"; // "n" with combining ~ character (U+0303)
![Page 20: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/20.jpg)
nAcademy Le 26 février 2015 Neuros
Introduce session_start()● Ajout d'une option● Lecture seule
– Un moyen rapide de lire les données de la session lorsque la mise à jour n'est pas nécessaire
● Ecriture en option– Les données ne sont pas écrites si elles sont identiques
Source : https://wiki.php.net/rfc/session-lock-ini
<?php
session_start(array('lazy_write'=False));
![Page 21: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/21.jpg)
nAcademy Le 26 février 2015 Neuros
Catchable ● 'call to a member function of a nonobject'● Pour éviter d'obtenir une erreur nonfatale
– E_RECOVERABLE_ERROR
● Cela se produit à chaque fois qu'une méthode est appelée sur autre chose qu'un objet
Source : https://wiki.php.net/rfc/catchable-call-to-member-of-non-object
<?php set_error_handler(function($code,$message) {
var_dump($code, $message);
});
$x= null;
var_dump($x->method());
echo "Alive\n";
![Page 22: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/22.jpg)
nAcademy Le 26 février 2015 Neuros
Uniform variable Syntax● Uniformisation de la Syntax variable● But : Atteindre la sémantique pour certaines
constructions variables
Source : https://wiki.php.net/rfc/uniform_variable_syntax
// old // new
$$foo['bar']['baz'] ${$foo['bar']['baz']} ($$foo)['bar']['baz']
$foo->$bar['baz'] $foo->{$bar['baz']} ($foo->$bar)['baz']
$foo->$bar['baz']() $foo->{$bar['baz']}() ($foo->$bar)['baz']()
Foo::$bar['baz']() Foo::{$bar['baz']}() (Foo::$bar)['baz']()
![Page 23: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/23.jpg)
nAcademy Le 26 février 2015 Neuros
Return Type Declarations● Possibilité de spécifier un type de retour
→ pour les fonctions et méthodes
Source : https://wiki.php.net/rfc/return_types
<?php
// retourne toujours un tableau
function foo(): array {
return [];
}
![Page 24: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/24.jpg)
nAcademy Le 26 février 2015 Neuros
Named parameters● Nommés les paramètres● Exemple// Remplit un tableau avec une même valeur
array_fill(start, num, value)
Source : https://wiki.php.net/rfc/named_params
<?php
// Actuellement
array_fill(0, 100, 42);
// Possibilité
array_fill(start_index => 0, num => 100, value => 42);
// ou
array_fill(value => 42, num => 100, start_index => 0);
![Page 25: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/25.jpg)
nAcademy Le 26 février 2015 Neuros
Et...● Beaucoup d'autres…. RFC…. pour PHP 7.0
https://wiki.php.net/rfc#php_70
Picture PHPather Spirituel : Vincent Pontier aka EL Roubio
![Page 26: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/26.jpg)
nAcademy Le 26 février 2015 Neuros
Features en cours (Votes/Discussions)● Exceptions in the engine (for PHP 7)
– Permettre la levée d'exceptions depuis le moteur de PHP
● Remove PHP 4 Constructors– Liés aux constructeurs. Depuis php5 __construct()→
● Expectations– Identifier les problèmes en Dev ( basé sur assert() )
● Array to string conversion– Convertir un Array en String
![Page 27: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/27.jpg)
nAcademy Le 26 février 2015 Neuros
PerformancePicture EL Roubio – http://www.elroubio.net
![Page 28: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/28.jpg)
nAcademy Le 26 février 2015 Neuros
Configuration● VM Debian 7 1GB RAM, 1 core, SSD
ulabox.com symfony 2 index / product page
PHP 5.5 / 5.6 / 7.0opcache.validate_timestamps = 0
opcache.enable_file_override = 1
HHVM 3.5Hhvm.server_stat_cache = 1
No extensions! (APCu)
Nginx, Redis, Solr, MySQLSource 31/01/2015 : https://speakerdeck.com/acasademont/php7atphpdayspain2015
![Page 29: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/29.jpg)
nAcademy Le 26 février 2015 Neuros
Résultat
Réalisation 31/01/2015 Source : https://speakerdeck.com/acasademont/php7atphpdayspain2015
![Page 30: PHP 7 - Think php7](https://reader031.fdocuments.net/reader031/viewer/2022012403/55a9482f1a28ab8c3e8b47dc/html5/thumbnails/30.jpg)
nAcademy Le 26 février 2015 Neuros
Merci
Questions ?
@hellosct1
@neuro_paris
Sources Pierre Joye Albert Casademont Internals rfc
Adoptionhttp://www.elephantphp.com
Except the human PHPather