SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Les nouveautés de PHP 7

et de Symfony 3.0
by RICHARD Eddy
APERO PHP 

23/02/2016
PHP 7
PHP Roadmap
Active support Security fixes only End of life
Sortie de PHP 7
3 décembre 2015
Nouveau logo :



PONTIER Vincent

http://elroubio.net
PHP 7 —> PHPNG (Next Generation)

https://wiki.php.net/phpng
Pourquoi PHP 7 ?
Pourquoi PHP 7 ?
Un seul mot 





PERFORMANCES
Incompatibilité
Suppression des fonctionnalités dépréciées
https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7
ext/mySQL
Exemple :
PDO_MySQL ou
MySQLi
(dépréciée depuis PHP5.5)
ext/ereg ext/pcre(dépréciée depuis PHP5.3)
Incompatibilité
Les constructeurs PHP 4 sont maintenant dépréciés !
https://wiki.php.net/rfc/remove_php4_constructors
<?php
class IlEtaitTemps {
public function iletaittemps() { … }
}
new IlEtaitTemps();
Les constructeurs PHP4 ne sont plus reconnus dans une
classe d’un namespace.
Incompatibilité
Certains types sont devenus des mots clés réservés pour les
noms de classes, traits et interfaces



https://wiki.php.net/rfc/reserve_more_types_in_php_7 

https://wiki.php.net/rfc/reserve_even_more_types_in_php_7
- int
- float
- bool
- string
- true
- false
- null
- resource
- object
- mixed
- numeric
<?php
class resource {
public function __construct() { … }
}
new resource();
Retourne une fatal erreur, Fatal error:
"resource" cannot be used as a classname
Incompatibilité
Suppression des ASP et script tags
<script language=”PHP”></script>
<% %>
<%= %>
Incompatibilité
switch n’accepte plus plusieurs default
<?php
switch ($expression) {
default:
echo 'Olá';
break;
default:
echo 'Tchau';
break;
}
Fatal error: Switch statements may
only contain one default clause
Incompatibilité
Un octal invalide produit maintenant une erreur
<?php
$octale = 0148;
echo $octale;
PHP 5.x PHP 7
Affiche 12 Fatal Error : Invalid numeric literal ….
Incompatibilité
Les chaînes de caractères hexadécimales ne sont plus reconnues
<?php
var_dump(is_numeric('0x143'));
PHP 5.x PHP 7
bool(true) bool(false)
Incompatibilité
Nouveau caractère u Permet de spécifier un caractère Unicode et
particulièrement UTF-8 (en hexadécimal)



https://wiki.php.net/rfc/unicode_escape
<?php
$unicode = "u{265C}";
echo $unicode;
Incompatibilité car u dans une double-quote ou HEREDOC
existant sera considéré comme un caractère Unicode.

Si celui-ci n’existe pas, une erreur fatale de compilation est levée
Incompatibilité
L’assignation du résultat d’un new par
référence n’est plus possible
<?php
$objet = &new stdclass;
Retourne une erreur de parser
Incompatibilité
La redéfinition d’un argument d’une fonction
n’est plus possible
<?php
function test($param, $valid, $valid) { … }
Retourne une erreur fatale : Fatal error: Redefinition of parameter $valid ….
Incompatibilité
Les 2 fonctions func_get_arg et func_get_args
retournent la valeur d’une variable dans le contexte local
<?php
function samba($samba) {
$samba++;
echo func_get_arg(0);
}
samba(2);
PHP 5.x PHP 7
Affiche 2 Affiche 3
Scalar type hinting
PHP7 offre la possibilité de spécifier un type scalaire
(string, integer, float, boolean) pour le type hinting



Activer en ajoutant declare(strict_types=1); en
première instruction du fichier
<?php
declare(strict_types=1);
function test(int $param) {
return $param;
}
echo test(1); echo test("1");
Affiche 1 Fatal error: Argument 1 passed to test()…
Return type declaration
Possibilité de définir le type de retour attendu 

Une catchable fatal error est retournée si le type ne correspond pas
<?php
function test(): DateTime {
return 1;
}
<?php
function test(): array { 

return [0,1,2];
}
Type de retour invalide
Type de retour valide
Les méthodes constructeurs, destructeurs et clones ne peuvent pas
déclarer de type de retour.
Group use declaration
Regroupement de déclaration use d’un namespace commun

https://wiki.php.net/rfc/group_use_declarations
<?php
use DarkmiraComponentSecurityClassA;
use DarkmiraComponentSecurityClassB;
use DarkmiraComponentBddClassC as classC;
<?php
use DarkmiraComponent{
SecurityClassA,
SecurityClassB,
BddClassC as classC
};
Anonymous Class
Même principe que les fonctions anonymes

https://wiki.php.net/rfc/return_types
<?php
class Log {
public function log ($msg) { … }
}
$obj->setLog(new Log());
<?php
$obj->setLog(new class {
public function log ($msg) { … }
});
Starship Operator
Opérateur de comparaison (Combined Comparison Operator)

https://wiki.php.net/rfc/combined-comparison-operator
- Identique aux fonctions strcmp()
et version_compare()
- Mais peut comparer tous les
types du moment qu’ils sont
identiques de part et d’autre de
l’opérateur : chaînes, array,
objets, ….
Retourne :
0 si égal
-1 si la valeur de gauche est
inférieure
1 si la valeur de droite est
inférieure
<?php
function order_func($a, $b) {
return
($a < $b) ? -1 : (($a > $b) ? 1 : 0)
;
}
<?php
function order_func($a, $b){
return $a <=> $b;
}
Null Coalesce Operator
L’opérateur ?? retourne le résultat de l’opération de gauche si
celui-ci n’est pas NULL sinon le résultat de l’opération de droite

https://wiki.php.net/rfc/isset_ternary
<?php
$name = isset($_GET['name']) ? $_GET['name'] : 'default';
<?php
$name = $_GET['name'] ?? 'default';
Enorme gain de
performances
+
Peu de BC Break
=
Migration assurée et rapide
Symfony 3.0
Roadmap
Sortie de SYMFONY 3.0 novembre 2015

http://symfony.com/doc/current/contributing/community/releases.html
Version LTS

(Long Term Support)
36 mois (3 ans)
2.x : 2.7 - 2.8
3.x : 3.4
Suppression des fonctions obsolètes
Version minimum de PHP revue à la hausse
5.5 —> 5.6
La version 2.8 (LTS) intègre les
fonctionnalisés de la version 3.0 en
conservant la rétro compatibilité avec les
précédentes versions.
Des changements dans son
architecture bas niveau
- Changement dans les signatures de méthode
- Remplacements et redéfinitions de classes et
méthodes
- Adaptation aux nouvelles normes PSR (Propose a
Standards Recommendation) http://www.php-fig.org/
-Modifications mineures d’architectures
- Modifications dans la structure des fichiers
Les normes PSR
PSR : Propose a Standards Recommendation
Recommandations validées par PHP Framework Interoperability
Group http://www.php-fig.org/
PSR-O : chargement des classes PHP et de l’autoloading
PSR-1 : fixe les conventions minimales de codage
PSR-2 : défini le style et l’organisation du code
PSR-3 : s’occupe de l’interface des loggers
… …
Architecture des fichiers :

SYMFONY 2.x VS SYMFONY 3.0
MERCI
@edrichardfr

Contenu connexe

Tendances

Symfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 PerformantSymfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 PerformantHugo Hamon
 
Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5Kristen Le Liboux
 
Formation PHP
Formation PHPFormation PHP
Formation PHPkemenaran
 
PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4julien pauli
 
ZendFramework2 - Présentation
ZendFramework2 - PrésentationZendFramework2 - Présentation
ZendFramework2 - Présentationjulien pauli
 
JavaScript prise en main et fondamentaux
JavaScript prise en main et fondamentauxJavaScript prise en main et fondamentaux
JavaScript prise en main et fondamentauxVincent Petetin
 
php2 : formulaire-session-PDO
php2 : formulaire-session-PDOphp2 : formulaire-session-PDO
php2 : formulaire-session-PDOAbdoulaye Dieng
 
PHP - get started
PHP - get startedPHP - get started
PHP - get startedmazenovi
 
Function oop - bonnes pratiques ms tech days
Function   oop - bonnes pratiques ms tech daysFunction   oop - bonnes pratiques ms tech days
Function oop - bonnes pratiques ms tech daysJean-Pierre Vincent
 
PHP #1 : introduction
PHP #1 : introductionPHP #1 : introduction
PHP #1 : introductionJean Michel
 
Notions de base de JavaScript
Notions de base de JavaScriptNotions de base de JavaScript
Notions de base de JavaScriptKristen Le Liboux
 
Migration PHP4-PHP5
Migration PHP4-PHP5Migration PHP4-PHP5
Migration PHP4-PHP5julien pauli
 
.php1 : les fondamentaux du PHP
.php1 : les fondamentaux du PHP.php1 : les fondamentaux du PHP
.php1 : les fondamentaux du PHPAbdoulaye Dieng
 
PHP 5.3, PHP Next
PHP 5.3, PHP NextPHP 5.3, PHP Next
PHP 5.3, PHP NextSQLI
 

Tendances (18)

Playing With PHP 5.3
Playing With PHP 5.3Playing With PHP 5.3
Playing With PHP 5.3
 
Symfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 PerformantSymfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 Performant
 
Langage Perl
Langage PerlLangage Perl
Langage Perl
 
Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5
 
Php cours
Php coursPhp cours
Php cours
 
Formation PHP
Formation PHPFormation PHP
Formation PHP
 
Cours php
Cours phpCours php
Cours php
 
PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4
 
ZendFramework2 - Présentation
ZendFramework2 - PrésentationZendFramework2 - Présentation
ZendFramework2 - Présentation
 
JavaScript prise en main et fondamentaux
JavaScript prise en main et fondamentauxJavaScript prise en main et fondamentaux
JavaScript prise en main et fondamentaux
 
php2 : formulaire-session-PDO
php2 : formulaire-session-PDOphp2 : formulaire-session-PDO
php2 : formulaire-session-PDO
 
PHP - get started
PHP - get startedPHP - get started
PHP - get started
 
Function oop - bonnes pratiques ms tech days
Function   oop - bonnes pratiques ms tech daysFunction   oop - bonnes pratiques ms tech days
Function oop - bonnes pratiques ms tech days
 
PHP #1 : introduction
PHP #1 : introductionPHP #1 : introduction
PHP #1 : introduction
 
Notions de base de JavaScript
Notions de base de JavaScriptNotions de base de JavaScript
Notions de base de JavaScript
 
Migration PHP4-PHP5
Migration PHP4-PHP5Migration PHP4-PHP5
Migration PHP4-PHP5
 
.php1 : les fondamentaux du PHP
.php1 : les fondamentaux du PHP.php1 : les fondamentaux du PHP
.php1 : les fondamentaux du PHP
 
PHP 5.3, PHP Next
PHP 5.3, PHP NextPHP 5.3, PHP Next
PHP 5.3, PHP Next
 

En vedette

CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 
Event sourcing with reactor and spring statemachine
Event sourcing with reactor and spring statemachineEvent sourcing with reactor and spring statemachine
Event sourcing with reactor and spring statemachineJimmy Lu
 
ConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con SymfonyConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con SymfonyLuca Saba
 
Design applicatif avec symfony2
Design applicatif avec symfony2Design applicatif avec symfony2
Design applicatif avec symfony2RomainKuzniak
 
Introduzione pratica a Symfony
Introduzione pratica a SymfonyIntroduzione pratica a Symfony
Introduzione pratica a SymfonyEugenio Minardi
 
Symfony in microservice architecture
Symfony in microservice architectureSymfony in microservice architecture
Symfony in microservice architectureDaniele D'Angeli
 
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Alexander Lisachenko
 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)Javier Eguiluz
 
Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3
Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3
Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3Tomáš Votruba
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2RomainKuzniak
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentationyllieth
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentationelliehood
 

En vedette (19)

CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
Spring statemachine
Spring statemachineSpring statemachine
Spring statemachine
 
Event sourcing with reactor and spring statemachine
Event sourcing with reactor and spring statemachineEvent sourcing with reactor and spring statemachine
Event sourcing with reactor and spring statemachine
 
Symfony ignite
Symfony igniteSymfony ignite
Symfony ignite
 
ConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con SymfonyConfSL: Sviluppo Applicazioni web con Symfony
ConfSL: Sviluppo Applicazioni web con Symfony
 
Design applicatif avec symfony2
Design applicatif avec symfony2Design applicatif avec symfony2
Design applicatif avec symfony2
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Symfony 3
Symfony 3Symfony 3
Symfony 3
 
Introduzione pratica a Symfony
Introduzione pratica a SymfonyIntroduzione pratica a Symfony
Introduzione pratica a Symfony
 
Symfony in microservice architecture
Symfony in microservice architectureSymfony in microservice architecture
Symfony in microservice architecture
 
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
 
Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3
Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3
Tomáš Votruba - Hot news! PHP 7.0, 7.1 a Symfony 3.1, 3.2 a 3.3
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
 
Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentation
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 

Similaire à PHP 7 et Symfony 3

Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Damien Seguy
 
Php 7.4 2020-01-28 - afup
Php 7.4   2020-01-28 - afupPhp 7.4   2020-01-28 - afup
Php 7.4 2020-01-28 - afupJulien Vinber
 
Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Wixiweb
 
Cours php -partie 1.pdf
Cours php -partie 1.pdfCours php -partie 1.pdf
Cours php -partie 1.pdfssuserc46a93
 
Cours Programmation web en PHP Cours Programmation web en PHP
Cours Programmation web en PHP Cours Programmation web en PHPCours Programmation web en PHP Cours Programmation web en PHP
Cours Programmation web en PHP Cours Programmation web en PHPBassim ELKHATTABY
 
Php 7 Think php7
Php 7 Think php7Php 7 Think php7
Php 7 Think php7neuros
 
Comment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguerComment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguerDamien Seguy
 
Php_Mysql.pdf
Php_Mysql.pdfPhp_Mysql.pdf
Php_Mysql.pdfETTAMRY
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5halleck45
 
PHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_ExtensionsPHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_Extensionsjulien pauli
 
Open close principle, on a dit étendre, pas extends !
Open close principle, on a dit étendre, pas extends !Open close principle, on a dit étendre, pas extends !
Open close principle, on a dit étendre, pas extends !Engineor
 
Les principes de base de PHP
 Les principes de base de PHP  Les principes de base de PHP
Les principes de base de PHP EL JAOUARI Ahmed
 

Similaire à PHP 7 et Symfony 3 (20)

Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4
 
Php 7.4 2020-01-28 - afup
Php 7.4   2020-01-28 - afupPhp 7.4   2020-01-28 - afup
Php 7.4 2020-01-28 - afup
 
Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]
 
Php 5.3
Php 5.3Php 5.3
Php 5.3
 
test doc
test doctest doc
test doc
 
Cours php -partie 1.pdf
Cours php -partie 1.pdfCours php -partie 1.pdf
Cours php -partie 1.pdf
 
Cours Programmation web en PHP Cours Programmation web en PHP
Cours Programmation web en PHP Cours Programmation web en PHPCours Programmation web en PHP Cours Programmation web en PHP
Cours Programmation web en PHP Cours Programmation web en PHP
 
Php seance1
Php seance1Php seance1
Php seance1
 
Php 7 Think php7
Php 7 Think php7Php 7 Think php7
Php 7 Think php7
 
PHP5: Endgame
PHP5: EndgamePHP5: Endgame
PHP5: Endgame
 
Php4 Mysql
Php4 MysqlPhp4 Mysql
Php4 Mysql
 
C# 7 - Nouveautés
C# 7 - NouveautésC# 7 - Nouveautés
C# 7 - Nouveautés
 
Comment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguerComment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguer
 
Php_Mysql.pdf
Php_Mysql.pdfPhp_Mysql.pdf
Php_Mysql.pdf
 
Chapitre 04 : les fonctions
Chapitre 04 : les fonctionsChapitre 04 : les fonctions
Chapitre 04 : les fonctions
 
Initiation au langage PHP
Initiation au langage PHPInitiation au langage PHP
Initiation au langage PHP
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5
 
PHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_ExtensionsPHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_Extensions
 
Open close principle, on a dit étendre, pas extends !
Open close principle, on a dit étendre, pas extends !Open close principle, on a dit étendre, pas extends !
Open close principle, on a dit étendre, pas extends !
 
Les principes de base de PHP
 Les principes de base de PHP  Les principes de base de PHP
Les principes de base de PHP
 

PHP 7 et Symfony 3

  • 1. Les nouveautés de PHP 7
 et de Symfony 3.0 by RICHARD Eddy APERO PHP 
 23/02/2016
  • 3. PHP Roadmap Active support Security fixes only End of life
  • 4. Sortie de PHP 7 3 décembre 2015 Nouveau logo :
 
 PONTIER Vincent
 http://elroubio.net PHP 7 —> PHPNG (Next Generation)
 https://wiki.php.net/phpng
  • 6. Pourquoi PHP 7 ? Un seul mot 
 
 
 PERFORMANCES
  • 7. Incompatibilité Suppression des fonctionnalités dépréciées https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7 ext/mySQL Exemple : PDO_MySQL ou MySQLi (dépréciée depuis PHP5.5) ext/ereg ext/pcre(dépréciée depuis PHP5.3)
  • 8. Incompatibilité Les constructeurs PHP 4 sont maintenant dépréciés ! https://wiki.php.net/rfc/remove_php4_constructors <?php class IlEtaitTemps { public function iletaittemps() { … } } new IlEtaitTemps(); Les constructeurs PHP4 ne sont plus reconnus dans une classe d’un namespace.
  • 9. Incompatibilité Certains types sont devenus des mots clés réservés pour les noms de classes, traits et interfaces
 
 https://wiki.php.net/rfc/reserve_more_types_in_php_7 
 https://wiki.php.net/rfc/reserve_even_more_types_in_php_7 - int - float - bool - string - true - false - null - resource - object - mixed - numeric <?php class resource { public function __construct() { … } } new resource(); Retourne une fatal erreur, Fatal error: "resource" cannot be used as a classname
  • 10. Incompatibilité Suppression des ASP et script tags <script language=”PHP”></script> <% %> <%= %>
  • 11. Incompatibilité switch n’accepte plus plusieurs default <?php switch ($expression) { default: echo 'Olá'; break; default: echo 'Tchau'; break; } Fatal error: Switch statements may only contain one default clause
  • 12. Incompatibilité Un octal invalide produit maintenant une erreur <?php $octale = 0148; echo $octale; PHP 5.x PHP 7 Affiche 12 Fatal Error : Invalid numeric literal ….
  • 13. Incompatibilité Les chaînes de caractères hexadécimales ne sont plus reconnues <?php var_dump(is_numeric('0x143')); PHP 5.x PHP 7 bool(true) bool(false)
  • 14. Incompatibilité Nouveau caractère u Permet de spécifier un caractère Unicode et particulièrement UTF-8 (en hexadécimal)
 
 https://wiki.php.net/rfc/unicode_escape <?php $unicode = "u{265C}"; echo $unicode; Incompatibilité car u dans une double-quote ou HEREDOC existant sera considéré comme un caractère Unicode.
 Si celui-ci n’existe pas, une erreur fatale de compilation est levée
  • 15. Incompatibilité L’assignation du résultat d’un new par référence n’est plus possible <?php $objet = &new stdclass; Retourne une erreur de parser
  • 16. Incompatibilité La redéfinition d’un argument d’une fonction n’est plus possible <?php function test($param, $valid, $valid) { … } Retourne une erreur fatale : Fatal error: Redefinition of parameter $valid ….
  • 17. Incompatibilité Les 2 fonctions func_get_arg et func_get_args retournent la valeur d’une variable dans le contexte local <?php function samba($samba) { $samba++; echo func_get_arg(0); } samba(2); PHP 5.x PHP 7 Affiche 2 Affiche 3
  • 18. Scalar type hinting PHP7 offre la possibilité de spécifier un type scalaire (string, integer, float, boolean) pour le type hinting
 
 Activer en ajoutant declare(strict_types=1); en première instruction du fichier <?php declare(strict_types=1); function test(int $param) { return $param; } echo test(1); echo test("1"); Affiche 1 Fatal error: Argument 1 passed to test()…
  • 19. Return type declaration Possibilité de définir le type de retour attendu 
 Une catchable fatal error est retournée si le type ne correspond pas <?php function test(): DateTime { return 1; } <?php function test(): array { 
 return [0,1,2]; } Type de retour invalide Type de retour valide Les méthodes constructeurs, destructeurs et clones ne peuvent pas déclarer de type de retour.
  • 20. Group use declaration Regroupement de déclaration use d’un namespace commun
 https://wiki.php.net/rfc/group_use_declarations <?php use DarkmiraComponentSecurityClassA; use DarkmiraComponentSecurityClassB; use DarkmiraComponentBddClassC as classC; <?php use DarkmiraComponent{ SecurityClassA, SecurityClassB, BddClassC as classC };
  • 21. Anonymous Class Même principe que les fonctions anonymes
 https://wiki.php.net/rfc/return_types <?php class Log { public function log ($msg) { … } } $obj->setLog(new Log()); <?php $obj->setLog(new class { public function log ($msg) { … } });
  • 22. Starship Operator Opérateur de comparaison (Combined Comparison Operator)
 https://wiki.php.net/rfc/combined-comparison-operator - Identique aux fonctions strcmp() et version_compare() - Mais peut comparer tous les types du moment qu’ils sont identiques de part et d’autre de l’opérateur : chaînes, array, objets, …. Retourne : 0 si égal -1 si la valeur de gauche est inférieure 1 si la valeur de droite est inférieure <?php function order_func($a, $b) { return ($a < $b) ? -1 : (($a > $b) ? 1 : 0) ; } <?php function order_func($a, $b){ return $a <=> $b; }
  • 23. Null Coalesce Operator L’opérateur ?? retourne le résultat de l’opération de gauche si celui-ci n’est pas NULL sinon le résultat de l’opération de droite
 https://wiki.php.net/rfc/isset_ternary <?php $name = isset($_GET['name']) ? $_GET['name'] : 'default'; <?php $name = $_GET['name'] ?? 'default';
  • 24. Enorme gain de performances + Peu de BC Break = Migration assurée et rapide
  • 26. Roadmap Sortie de SYMFONY 3.0 novembre 2015
 http://symfony.com/doc/current/contributing/community/releases.html
  • 27. Version LTS
 (Long Term Support) 36 mois (3 ans) 2.x : 2.7 - 2.8 3.x : 3.4
  • 28. Suppression des fonctions obsolètes Version minimum de PHP revue à la hausse 5.5 —> 5.6
  • 29. La version 2.8 (LTS) intègre les fonctionnalisés de la version 3.0 en conservant la rétro compatibilité avec les précédentes versions.
  • 30. Des changements dans son architecture bas niveau - Changement dans les signatures de méthode - Remplacements et redéfinitions de classes et méthodes - Adaptation aux nouvelles normes PSR (Propose a Standards Recommendation) http://www.php-fig.org/ -Modifications mineures d’architectures - Modifications dans la structure des fichiers
  • 31. Les normes PSR PSR : Propose a Standards Recommendation Recommandations validées par PHP Framework Interoperability Group http://www.php-fig.org/ PSR-O : chargement des classes PHP et de l’autoloading PSR-1 : fixe les conventions minimales de codage PSR-2 : défini le style et l’organisation du code PSR-3 : s’occupe de l’interface des loggers … …
  • 32. Architecture des fichiers :
 SYMFONY 2.x VS SYMFONY 3.0
  • 33.