Rapide Advanced Adulte
 
 Web|Image|Shop|Video|News|Wmx|Mobile|Wiki|Ajouter ce moteur

     Manuel PHP     
Partager
 
 
Partager
Partager

 

Table :

.Histoire de PHP
.Migration de PHP 4 à PHP 5
.Migration de PHP 3 à PHP 4
.Migration de PHP/FI 2 à PHP 3
.Débogueur PHP
.Options de configuration
.Directives du php.ini
.Liste des Fuseaux Horaires Supportés
.Catégorie des extensions
.Liste des alias
.Mots réservés en PHP
.Types des ressources PHP
.Liste des protocoles supportés
.Liste des filtres standards
.Liste des modes de transport de sockets disponibles
.Comparaison de types en PHP
.Liste des tokens de l'analyseur
.Guide de nommage de l'espace utilisateur
.À propos du manuel
.Open Publication License
.Index des fonctions
.Eléments Absents
 
   

  types comparisons  


Annexe P. Comparaison de types en PHP

La table suivante résume les différents comportements de PHP avec les types et opérateurs de comparaison, strictes ou larges. Cette table est aussi reliée au transtypage. Elle a été inspirée par différents commentaires d'utilisateurs, et par le travail fait chez BlueShoes.

Avant d'utiliser ces tables, il est important de comprendre les types et leur signification. Par exemple, "42" est une chaîne de caractères, alors que 42 est un entier. FALSE est boolean alors que "false" est une chaîne de caractères.

Note : Les formulaires HTML ne connaissent pas les entiers, nombres à virgules et autres booléens. Pour savoir si une structure est un entier, utilisez is_numeric().

Note : La ligne if ($x) génère une erreur de niveau E_NOTICE lorsque $x est indéfini. Alternativement, utilisez plutôt les fonctions empty() ou isset(), ou encore, initialisez toutes vos variables.

Tableau P-1. Comparaisons de $x avec des fonctions PHP

Expressiongettype()empty()is_null()isset()boolean : if($x)
$x = "";chaîne de caractèresTRUEFALSETRUEFALSE
$x = NULLNULLTRUETRUEFALSEFALSE
var $x;NULLTRUETRUEFALSEFALSE
$x est indéfiniNULLTRUETRUEFALSEFALSE
$x = array();arrayTRUEFALSETRUEFALSE
$x = false;booleanTRUEFALSETRUEFALSE
$x = true;booleanFALSEFALSETRUETRUE
$x = 1;entierFALSEFALSETRUETRUE
$x = 42;entierFALSEFALSETRUETRUE
$x = 0;entierTRUEFALSETRUEFALSE
$x = -1;entierFALSEFALSETRUETRUE
$x = "1";chaîne de caractèresFALSEFALSETRUETRUE
$x = "0";chaîne de caractèresTRUEFALSETRUEFALSE
$x = "-1";chaîne de caractèresFALSEFALSETRUETRUE
$x = "php";chaîne de caractèresFALSEFALSETRUETRUE
$x = "true";chaîne de caractèresFALSEFALSETRUETRUE
$x = "false";chaîne de caractèresFALSEFALSETRUETRUE

Tableau P-2. Comparaison large avec ==

 TRUEFALSE10-1"1""0""-1"NULLarray()"php"""
TRUETRUEFALSETRUEFALSETRUETRUEFALSETRUEFALSEFALSETRUEFALSE
FALSEFALSETRUEFALSETRUEFALSEFALSETRUEFALSETRUETRUEFALSETRUE
1TRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE
0FALSETRUEFALSETRUEFALSEFALSETRUEFALSETRUEFALSETRUETRUE
-1TRUEFALSEFALSEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSE
"1"TRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE
"0"FALSETRUEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSE
"-1"TRUEFALSEFALSEFALSETRUEFALSEFALSETRUEFALSEFALSEFALSEFALSE
NULLFALSETRUEFALSETRUEFALSEFALSEFALSEFALSETRUETRUEFALSETRUE
array()FALSETRUEFALSEFALSEFALSEFALSEFALSEFALSETRUETRUEFALSEFALSE
"php"TRUEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSE
""FALSETRUEFALSETRUEFALSEFALSEFALSEFALSETRUEFALSEFALSETRUE

Tableau P-3. Comparaison stricte avec ===

 TRUEFALSE10-1"1""0""-1"NULLarray()"php"""
TRUETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
FALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
1FALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
0FALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
-1FALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
"1"FALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE
"0"FALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSE
"-1"FALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSE
NULLFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSE
array()FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSE
"php"FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSE
""FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUE

Note PHP 3.0 : La chaîne de valeur "0" était considérée comme non vide en PHP 3. Ce comportement a changé en PHP 4, où elle est désormais considérée comme vide.


    Annonces       
 

 Retour au chapitre Php

 

Top
 

Ajouter JungleKey.fr à votre Explorateur

 
 

About Us | © 2007 JungleKey




iBlack | Mobile | Wiki | Ajouter ce moteur
.