SlideShare a Scribd company logo
1 of 47
Scalar Types Hints
Webinar PHParty7 France - 28/11/15
Historique
• PHP 5.0
Support des types non scalaires liés à la POO (Classes, Interfaces,
mot-clé self)
• PHP 5.1
Support des tableaux (mot-clé array)
• PHP 5.4
Support des fonctions de rappel (type Callable)
• PHP 7
Support des types scalaires (string, int, float, bool)
Rappels - Classes
Rappels - Classes
Affiche :
PHP7
Fatal error: Uncaught TypeError: Argument 1
passed to printList() must be an instance of
ArrayObject, instance of ArrayIterator given, called
in ... on line 10 and defined in ...:2
Rappels - Interfaces
Rappels - Interfaces
Affiche :
PHP7
PHP7
Fatal error: Uncaught TypeError: Argument 1
passed to printList() must implement interface
ArrayAccess, array given, called in ... on line 10
and defined in ...:2
Rappels - Tableaux
Rappels - Tableaux
Affiche :
PHP7
Fatal error: Uncaught TypeError: Argument 1
passed to printList() must be of the type array,
object given, called in ... on line 9 and defined in
...:2
Rappels - Fonctions de rappel
Rappels - Fonctions de rappel
Affiche :
PHP7
Aucune sortie
Fatal error: Uncaught TypeError: Argument 2
passed to printList() must be callable, string given,
called in ... on line 11 and defined in ...:2
PHP7 Scalar Type Hint
PHP7 Scalar Type Hint
• Types scalaires (primitifs)
• Chaînes de caractères (mot-clé string)
• Nombres décimaux entiers (mot-clé int)
• Nombres décimaux à virgules flottantes (float)
• Booléens (bool)
PHP7 Scalar Type Hint
• Types scalaires (primitifs)
• Chaînes de caractères (mot-clé string)
• Nombres décimaux entiers (mot-clé int)
• Nombres décimaux à virgules flottantes (float)
• Booléens (bool)
• Désactivé par défaut
PHP7 Scalar Type Hint
• Types scalaires (primitifs)
• Chaînes de caractères (mot-clé string)
• Nombres décimaux entiers (mot-clé int)
• Nombres décimaux à virgules flottantes (float)
• Booléens (bool)
• Désactivé par défaut
• Activé à l’aide de l’instruction declare(strict_types=1); en
début de fichier.
PHP7 Scalar Type Hint
• Types scalaires (primitifs)
• Chaînes de caractères (mot-clé string)
• Nombres décimaux entiers (mot-clé int)
• Nombres décimaux à virgules flottantes (float)
• Booléens (bool)
• Désactivé par défaut
• Activé à l’aide de l’instruction declare(strict_types=1); en
début de fichier.
• Activé uniquement sur le fichier ou l’instruction est
présente.
PHP7 Scalar Type Hint
• Types scalaires (primitifs)
• Chaînes de caractères (mot-clé string)
• Nombres décimaux entiers (mot-clé int)
• Nombres décimaux à virgules flottantes (float)
• Booléens (bool)
• Désactivé par défaut
• Activé à l’aide de l’instruction declare(strict_types=1); en
début de fichier.
• Activé uniquement sur le fichier ou l’instruction est
présente.
• Déclaration : function a(int $a) {...}
PHP7 Scalar Type Hint
• Types scalaires (primitifs)
• Chaînes de caractères (mot-clé string)
• Nombres décimaux entiers (mot-clé int)
• Nombres décimaux à virgules flottantes (float)
• Booléens (bool)
• Désactivé par défaut
• Activé à l’aide de l’instruction declare(strict_types=1); en
début de fichier.
• Activé uniquement sur le fichier ou l’instruction est
présente.
• Déclaration : function a(int $a) {...}
• Exception dédiée : TypeError
Scalar Type Hint - strict type
Scalar Type Hint - strict type
Affiche :
3
Fatal error: Uncaught TypeError: Argument 1
passed to sum() must be of the type integer, float
given, called in ... on line 9 and defined in ...:4
Scalar Type Hint - weak type
Scalar Type Hint - weak type
Affiche :
3
2
Scalar Type Hint - strict type -
string exemple
Affiche :
PHP 7
Fatal error: Uncaught TypeError: Argument 2
passed to concat() must be of the type string,
integer given, called in ... on line 9 and defined in
...:4
Scalar Type Hint - arguments
variables
Scalar Type Hint - arguments
variables
Affiche :
10
Fatal error: Uncaught TypeError: Argument 4
passed to sum() must be of the type integer,
string given, called in ... on line 9 and defined in
...:4
Scalar Type Hint - exception
Scalar Type Hint - exception
Affiche :
Erreur de type : Argument 1 passed to sum() must
be of the type integer,
float given, called in ... on line 9
Scalar Type Hint - null type
Scalar Type Hint - null type
Affiche :
Fatal error: Uncaught TypeError: Argument 1
passed to returnAsItIs() must be of the type
integer, null given, called in ... on line 12 and
defined in ...:4
Scalar Type Hint - effet local
Scalar Type Hint - effet local
Affiche :
3
2
Avantages
• Optionnel (typage faible par défaut)
• Moins de code
• Moins de documentation
• Code plus robuste
• force le développeur à identifier les E/S de ses
fonctions/méthodes
• permet à l’interpréteur de repérer les
dysfonctionnements avant l’utilisateur
• permet de consommer un service en toute
sérénité
Avantages - moins de code,
moins de doc (1)
Avantages - moins de code,
moins de doc (2)
Avantages - code plus
robuste (1-1)
Affiche :
4
4
Avantages - code plus
robuste (1-2)
Affiche :
Notice: A non well formed numeric value
encountered in ... on line 2
4
Notice: A non well formed numeric value
encountered in ... on line 2
4
Avantages - code plus
robuste (1-3)
Affiche :
Fatal error: Uncaught TypeError: Argument 2
passed to sum() must be of the type integer,
string given, called in ... on line 8 and defined in
...:4
Avantages - code plus
robuste (2-1)
Avantages - code plus
robuste (2-2)
Avantages - code plus
robuste (2-2)
Autre avantages...
• Sécurité accrue (filtrer les données entrantes,
échapper les données sortantes !)
• Écriture des tests simplifiée (moins d’assertion,
moins de test)
• Gain de performance (compilation en Opcode plus
facile)
Avantages - tests unitaires
simplifiés
Avantages - tests unitaires
simplifiés
Avantages - tests unitaires
simplifiés
Avantages - tests unitaires
simplifiés
Avantages - tests unitaires
simplifiés
Avantages - tests unitaires
simplifiés
Des questions ?

More Related Content

What's hot

Csharp1 : quelques elements de base
Csharp1 :  quelques elements de baseCsharp1 :  quelques elements de base
Csharp1 : quelques elements de baseAbdoulaye Dieng
 
Interface collectionsinter
Interface collectionsinterInterface collectionsinter
Interface collectionsinterRYMAA
 
OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder RUDDER
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmiqueAbdoulaye Dieng
 
cour de compilation
cour de compilation cour de compilation
cour de compilation Ens Kouba
 
Les fondamentaux du langage C
Les fondamentaux du langage CLes fondamentaux du langage C
Les fondamentaux du langage CAbdoulaye Dieng
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmiqueAbdoulaye Dieng
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmiqueAbdoulaye Dieng
 
Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5Mamadou Oury Ba
 
Programmation fonctionnelle
Programmation fonctionnelleProgrammation fonctionnelle
Programmation fonctionnelleJean Detoeuf
 
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018Loic Yon
 
Introduction à l’orienté objet en Python
Introduction à l’orienté objet en PythonIntroduction à l’orienté objet en Python
Introduction à l’orienté objet en PythonAbdoulaye Dieng
 
Formation python micro club.net
Formation python micro club.netFormation python micro club.net
Formation python micro club.netZakaria SMAHI
 
Cpp2 : classes et objets
Cpp2 : classes et objetsCpp2 : classes et objets
Cpp2 : classes et objetsAbdoulaye Dieng
 
Csharp3 heritage-polymorphisme-interface
Csharp3 heritage-polymorphisme-interfaceCsharp3 heritage-polymorphisme-interface
Csharp3 heritage-polymorphisme-interfaceAbdoulaye Dieng
 

What's hot (20)

Csharp1 : quelques elements de base
Csharp1 :  quelques elements de baseCsharp1 :  quelques elements de base
Csharp1 : quelques elements de base
 
Introduction à Python
Introduction à PythonIntroduction à Python
Introduction à Python
 
Interface collectionsinter
Interface collectionsinterInterface collectionsinter
Interface collectionsinter
 
OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmique
 
cour de compilation
cour de compilation cour de compilation
cour de compilation
 
Les fondamentaux du langage C
Les fondamentaux du langage CLes fondamentaux du langage C
Les fondamentaux du langage C
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmique
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmique
 
Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5
 
Cours tp2
Cours tp2Cours tp2
Cours tp2
 
Programmation fonctionnelle
Programmation fonctionnelleProgrammation fonctionnelle
Programmation fonctionnelle
 
Python
PythonPython
Python
 
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
Java - Support etudiant - Tronc Commun Deuxième année ISIMA - 2018
 
Introduction à l’orienté objet en Python
Introduction à l’orienté objet en PythonIntroduction à l’orienté objet en Python
Introduction à l’orienté objet en Python
 
Formation python micro club.net
Formation python micro club.netFormation python micro club.net
Formation python micro club.net
 
Formation python
Formation pythonFormation python
Formation python
 
Les listes en Python
Les listes en PythonLes listes en Python
Les listes en Python
 
Cpp2 : classes et objets
Cpp2 : classes et objetsCpp2 : classes et objets
Cpp2 : classes et objets
 
Csharp3 heritage-polymorphisme-interface
Csharp3 heritage-polymorphisme-interfaceCsharp3 heritage-polymorphisme-interface
Csharp3 heritage-polymorphisme-interface
 

Viewers also liked

Apakah mikrokontroler itu
Apakah mikrokontroler ituApakah mikrokontroler itu
Apakah mikrokontroler ituKania Sawitri
 
Año Europeo de los Ciudadanos 13 14
Año Europeo de los Ciudadanos 13 14Año Europeo de los Ciudadanos 13 14
Año Europeo de los Ciudadanos 13 14BestEuropa
 
Presentacion hardware
Presentacion hardwarePresentacion hardware
Presentacion hardware57430353
 
BC Breaks - Incompatibilites PHP7
BC Breaks - Incompatibilites PHP7BC Breaks - Incompatibilites PHP7
BC Breaks - Incompatibilites PHP7Darkmira
 
Каталог 03/2016
Каталог 03/2016Каталог 03/2016
Каталог 03/2016SvetaAvon
 
2.Το ανάκτορο της Κνωσού
2.Το ανάκτορο της Κνωσού2.Το ανάκτορο της Κνωσού
2.Το ανάκτορο της Κνωσούolgaporpori
 

Viewers also liked (14)

Apakah mikrokontroler itu
Apakah mikrokontroler ituApakah mikrokontroler itu
Apakah mikrokontroler itu
 
risk-awards-2015
risk-awards-2015risk-awards-2015
risk-awards-2015
 
Rpp
RppRpp
Rpp
 
Between Two Worlds
Between Two WorldsBetween Two Worlds
Between Two Worlds
 
Vfpc consulting
Vfpc consultingVfpc consulting
Vfpc consulting
 
Año Europeo de los Ciudadanos 13 14
Año Europeo de los Ciudadanos 13 14Año Europeo de los Ciudadanos 13 14
Año Europeo de los Ciudadanos 13 14
 
Presentacion hardware
Presentacion hardwarePresentacion hardware
Presentacion hardware
 
BC Breaks - Incompatibilites PHP7
BC Breaks - Incompatibilites PHP7BC Breaks - Incompatibilites PHP7
BC Breaks - Incompatibilites PHP7
 
Каталог 03/2016
Каталог 03/2016Каталог 03/2016
Каталог 03/2016
 
Ouvir atentamente
Ouvir atentamenteOuvir atentamente
Ouvir atentamente
 
Hardware
HardwareHardware
Hardware
 
2.Το ανάκτορο της Κνωσού
2.Το ανάκτορο της Κνωσού2.Το ανάκτορο της Κνωσού
2.Το ανάκτορο της Κνωσού
 
Resume (Autosaved)
Resume (Autosaved)Resume (Autosaved)
Resume (Autosaved)
 
Silabus
SilabusSilabus
Silabus
 

Similar to Scalar Types Hints

Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5halleck45
 
intro-csharp developement master 2 IF APP
intro-csharp developement master 2 IF APPintro-csharp developement master 2 IF APP
intro-csharp developement master 2 IF APPfrwebhelp
 
Introduction au langage python notion de base
Introduction au langage python notion de baseIntroduction au langage python notion de base
Introduction au langage python notion de basemohamedAitomar1
 
Introduction au langage python (Notion de base)
Introduction au langage python (Notion de base)Introduction au langage python (Notion de base)
Introduction au langage python (Notion de base)mohamedAitomar1
 
INF120 - Algo DUT SRC1 - Cours 3
INF120 - Algo DUT SRC1 - Cours 3INF120 - Algo DUT SRC1 - Cours 3
INF120 - Algo DUT SRC1 - Cours 3PGambette
 
Mix it 2011 - Clojure
Mix it 2011 - ClojureMix it 2011 - Clojure
Mix it 2011 - Clojurelolopetit
 
Langage de Programmation.pdf
Langage de Programmation.pdfLangage de Programmation.pdf
Langage de Programmation.pdfAboubacarDiarra10
 
Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#
Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#
Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#MSDEVMTL
 
Developpement web dynamique_Base de donnees.pdf
Developpement web dynamique_Base de donnees.pdfDeveloppement web dynamique_Base de donnees.pdf
Developpement web dynamique_Base de donnees.pdfrachidimstapha
 
Java-3eme partie.pptx
Java-3eme partie.pptxJava-3eme partie.pptx
Java-3eme partie.pptxHassanAbdel
 
Eléments du langage Java.pdf
Eléments du langage  Java.pdfEléments du langage  Java.pdf
Eléments du langage Java.pdfAabidiHafid
 
Chap 1 Initiation.pptx
Chap 1 Initiation.pptxChap 1 Initiation.pptx
Chap 1 Initiation.pptxolfaharrabi2
 
Chapitre1: Langage Python
Chapitre1: Langage PythonChapitre1: Langage Python
Chapitre1: Langage PythonAziz Darouichi
 
Développement Web- PHP (partie I).pdf
Développement Web- PHP (partie I).pdfDéveloppement Web- PHP (partie I).pdf
Développement Web- PHP (partie I).pdfYasushiTsubakik
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJosé Paumard
 

Similar to Scalar Types Hints (20)

Langage Perl
Langage PerlLangage Perl
Langage Perl
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5
 
intro-csharp developement master 2 IF APP
intro-csharp developement master 2 IF APPintro-csharp developement master 2 IF APP
intro-csharp developement master 2 IF APP
 
Introduction au langage python notion de base
Introduction au langage python notion de baseIntroduction au langage python notion de base
Introduction au langage python notion de base
 
Introduction au langage python (Notion de base)
Introduction au langage python (Notion de base)Introduction au langage python (Notion de base)
Introduction au langage python (Notion de base)
 
Nouveautés de java 8
Nouveautés de java 8Nouveautés de java 8
Nouveautés de java 8
 
INF120 - Algo DUT SRC1 - Cours 3
INF120 - Algo DUT SRC1 - Cours 3INF120 - Algo DUT SRC1 - Cours 3
INF120 - Algo DUT SRC1 - Cours 3
 
fortran 2.pdf
fortran 2.pdffortran 2.pdf
fortran 2.pdf
 
Mix it 2011 - Clojure
Mix it 2011 - ClojureMix it 2011 - Clojure
Mix it 2011 - Clojure
 
Langage de Programmation.pdf
Langage de Programmation.pdfLangage de Programmation.pdf
Langage de Programmation.pdf
 
Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#
Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#
Kevin Olivier Avignon: Une introduction à la pensée fonctionnelle avec F#
 
Developpement web dynamique_Base de donnees.pdf
Developpement web dynamique_Base de donnees.pdfDeveloppement web dynamique_Base de donnees.pdf
Developpement web dynamique_Base de donnees.pdf
 
Java-3eme partie.pptx
Java-3eme partie.pptxJava-3eme partie.pptx
Java-3eme partie.pptx
 
Eléments du langage Java.pdf
Eléments du langage  Java.pdfEléments du langage  Java.pdf
Eléments du langage Java.pdf
 
cours1.ppt
cours1.pptcours1.ppt
cours1.ppt
 
Chap 1 Initiation.pptx
Chap 1 Initiation.pptxChap 1 Initiation.pptx
Chap 1 Initiation.pptx
 
Drools
DroolsDrools
Drools
 
Chapitre1: Langage Python
Chapitre1: Langage PythonChapitre1: Langage Python
Chapitre1: Langage Python
 
Développement Web- PHP (partie I).pdf
Développement Web- PHP (partie I).pdfDéveloppement Web- PHP (partie I).pdf
Développement Web- PHP (partie I).pdf
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 

More from Darkmira

Null Coalescing Operator
Null Coalescing OperatorNull Coalescing Operator
Null Coalescing OperatorDarkmira
 
Return Type Declaration
Return Type DeclarationReturn Type Declaration
Return Type DeclarationDarkmira
 
Uniform Variable Syntax
Uniform Variable SyntaxUniform Variable Syntax
Uniform Variable SyntaxDarkmira
 
Le spaceship operator
Le spaceship operatorLe spaceship operator
Le spaceship operatorDarkmira
 
Anonymous classes
Anonymous classesAnonymous classes
Anonymous classesDarkmira
 
Benchmark php7
Benchmark php7Benchmark php7
Benchmark php7Darkmira
 
Webinar PHParty7 - Errors handlings
Webinar PHParty7 - Errors handlingsWebinar PHParty7 - Errors handlings
Webinar PHParty7 - Errors handlingsDarkmira
 

More from Darkmira (7)

Null Coalescing Operator
Null Coalescing OperatorNull Coalescing Operator
Null Coalescing Operator
 
Return Type Declaration
Return Type DeclarationReturn Type Declaration
Return Type Declaration
 
Uniform Variable Syntax
Uniform Variable SyntaxUniform Variable Syntax
Uniform Variable Syntax
 
Le spaceship operator
Le spaceship operatorLe spaceship operator
Le spaceship operator
 
Anonymous classes
Anonymous classesAnonymous classes
Anonymous classes
 
Benchmark php7
Benchmark php7Benchmark php7
Benchmark php7
 
Webinar PHParty7 - Errors handlings
Webinar PHParty7 - Errors handlingsWebinar PHParty7 - Errors handlings
Webinar PHParty7 - Errors handlings
 

Scalar Types Hints

  • 1. Scalar Types Hints Webinar PHParty7 France - 28/11/15
  • 2. Historique • PHP 5.0 Support des types non scalaires liés à la POO (Classes, Interfaces, mot-clé self) • PHP 5.1 Support des tableaux (mot-clé array) • PHP 5.4 Support des fonctions de rappel (type Callable) • PHP 7 Support des types scalaires (string, int, float, bool)
  • 4. Rappels - Classes Affiche : PHP7 Fatal error: Uncaught TypeError: Argument 1 passed to printList() must be an instance of ArrayObject, instance of ArrayIterator given, called in ... on line 10 and defined in ...:2
  • 6. Rappels - Interfaces Affiche : PHP7 PHP7 Fatal error: Uncaught TypeError: Argument 1 passed to printList() must implement interface ArrayAccess, array given, called in ... on line 10 and defined in ...:2
  • 8. Rappels - Tableaux Affiche : PHP7 Fatal error: Uncaught TypeError: Argument 1 passed to printList() must be of the type array, object given, called in ... on line 9 and defined in ...:2
  • 10. Rappels - Fonctions de rappel Affiche : PHP7 Aucune sortie Fatal error: Uncaught TypeError: Argument 2 passed to printList() must be callable, string given, called in ... on line 11 and defined in ...:2
  • 12. PHP7 Scalar Type Hint • Types scalaires (primitifs) • Chaînes de caractères (mot-clé string) • Nombres décimaux entiers (mot-clé int) • Nombres décimaux à virgules flottantes (float) • Booléens (bool)
  • 13. PHP7 Scalar Type Hint • Types scalaires (primitifs) • Chaînes de caractères (mot-clé string) • Nombres décimaux entiers (mot-clé int) • Nombres décimaux à virgules flottantes (float) • Booléens (bool) • Désactivé par défaut
  • 14. PHP7 Scalar Type Hint • Types scalaires (primitifs) • Chaînes de caractères (mot-clé string) • Nombres décimaux entiers (mot-clé int) • Nombres décimaux à virgules flottantes (float) • Booléens (bool) • Désactivé par défaut • Activé à l’aide de l’instruction declare(strict_types=1); en début de fichier.
  • 15. PHP7 Scalar Type Hint • Types scalaires (primitifs) • Chaînes de caractères (mot-clé string) • Nombres décimaux entiers (mot-clé int) • Nombres décimaux à virgules flottantes (float) • Booléens (bool) • Désactivé par défaut • Activé à l’aide de l’instruction declare(strict_types=1); en début de fichier. • Activé uniquement sur le fichier ou l’instruction est présente.
  • 16. PHP7 Scalar Type Hint • Types scalaires (primitifs) • Chaînes de caractères (mot-clé string) • Nombres décimaux entiers (mot-clé int) • Nombres décimaux à virgules flottantes (float) • Booléens (bool) • Désactivé par défaut • Activé à l’aide de l’instruction declare(strict_types=1); en début de fichier. • Activé uniquement sur le fichier ou l’instruction est présente. • Déclaration : function a(int $a) {...}
  • 17. PHP7 Scalar Type Hint • Types scalaires (primitifs) • Chaînes de caractères (mot-clé string) • Nombres décimaux entiers (mot-clé int) • Nombres décimaux à virgules flottantes (float) • Booléens (bool) • Désactivé par défaut • Activé à l’aide de l’instruction declare(strict_types=1); en début de fichier. • Activé uniquement sur le fichier ou l’instruction est présente. • Déclaration : function a(int $a) {...} • Exception dédiée : TypeError
  • 18. Scalar Type Hint - strict type
  • 19. Scalar Type Hint - strict type Affiche : 3 Fatal error: Uncaught TypeError: Argument 1 passed to sum() must be of the type integer, float given, called in ... on line 9 and defined in ...:4
  • 20. Scalar Type Hint - weak type
  • 21. Scalar Type Hint - weak type Affiche : 3 2
  • 22. Scalar Type Hint - strict type - string exemple Affiche : PHP 7 Fatal error: Uncaught TypeError: Argument 2 passed to concat() must be of the type string, integer given, called in ... on line 9 and defined in ...:4
  • 23. Scalar Type Hint - arguments variables
  • 24. Scalar Type Hint - arguments variables Affiche : 10 Fatal error: Uncaught TypeError: Argument 4 passed to sum() must be of the type integer, string given, called in ... on line 9 and defined in ...:4
  • 25. Scalar Type Hint - exception
  • 26. Scalar Type Hint - exception Affiche : Erreur de type : Argument 1 passed to sum() must be of the type integer, float given, called in ... on line 9
  • 27. Scalar Type Hint - null type
  • 28. Scalar Type Hint - null type Affiche : Fatal error: Uncaught TypeError: Argument 1 passed to returnAsItIs() must be of the type integer, null given, called in ... on line 12 and defined in ...:4
  • 29. Scalar Type Hint - effet local
  • 30. Scalar Type Hint - effet local Affiche : 3 2
  • 31. Avantages • Optionnel (typage faible par défaut) • Moins de code • Moins de documentation • Code plus robuste • force le développeur à identifier les E/S de ses fonctions/méthodes • permet à l’interpréteur de repérer les dysfonctionnements avant l’utilisateur • permet de consommer un service en toute sérénité
  • 32. Avantages - moins de code, moins de doc (1)
  • 33. Avantages - moins de code, moins de doc (2)
  • 34. Avantages - code plus robuste (1-1) Affiche : 4 4
  • 35. Avantages - code plus robuste (1-2) Affiche : Notice: A non well formed numeric value encountered in ... on line 2 4 Notice: A non well formed numeric value encountered in ... on line 2 4
  • 36. Avantages - code plus robuste (1-3) Affiche : Fatal error: Uncaught TypeError: Argument 2 passed to sum() must be of the type integer, string given, called in ... on line 8 and defined in ...:4
  • 37. Avantages - code plus robuste (2-1)
  • 38. Avantages - code plus robuste (2-2)
  • 39. Avantages - code plus robuste (2-2)
  • 40. Autre avantages... • Sécurité accrue (filtrer les données entrantes, échapper les données sortantes !) • Écriture des tests simplifiée (moins d’assertion, moins de test) • Gain de performance (compilation en Opcode plus facile)
  • 41. Avantages - tests unitaires simplifiés
  • 42. Avantages - tests unitaires simplifiés
  • 43. Avantages - tests unitaires simplifiés
  • 44. Avantages - tests unitaires simplifiés
  • 45. Avantages - tests unitaires simplifiés
  • 46. Avantages - tests unitaires simplifiés