PHP 8.3.4 Released!

variant_xor

(PHP 5, PHP 7, PHP 8)

variant_xorExécute une exclusion logique sur deux variants

Description

variant_xor(mixed $left, mixed $right): variant

Exécute une exclusion logique sur deux variants.

Liste de paramètres

left

L'opérande de gauche.

right

L'opérande de droite.

Note:

Comme pour toutes les fonctions arithmétiques, les paramètres pour cette fonction peuvent être soit un type PHP natif (entier, chaîne de caractères, nombre à virgule flottante, booléen ou null), ou une instance de la classe COM, VARIANT ou DOTNET. Les types PHP natifs seront convertis en VARIANT en utilisant les mêmes règles que celles trouvées dans le constructeur de la classe variant. Les objets COM et DOTNET auront la valeur de leur propriété par défaut récupérée et utilisée en tant que valeur VARIANT.

Les fonctions arithmétiques VARIANT sont interfacées sur les fonctions de la bibliothèque COM équivalentes ; pour plus d'informations sur ces fonctions, veuillez consulter la bibliothèque MSDN. Les fonctions PHP sont nommées de façon légèrement différentes : par exemple, variant_add(), en PHP, correspond à VarAdd() dans la documentation MSDN.

Valeurs de retour

Règles XOR pour les Variant
Si left est Si right est alors le résultat est
truetruefalse
truefalsetrue
falsetruetrue
falsefalsefalse
nullnullnull

Erreurs / Exceptions

Lance une com_exception en cas d'échec.

Voir aussi

  • variant_or() - Performe une disjonction logique sur deux variants
  • variant_and() - Effectue un ET entre deux variants et retourne le résultat

add a note

User Contributed Notes 3 notes

up
2
tinelbarb at yahoo dot com
13 years ago
I've been using a lot the VARIANT_XOR function (all the VARIANT functions ar cool) and I was faceing the problem that some custom copilation of PHP, especially LAMP packs, doesn't have the VARANT functions included, so the scripts halts.
I had to find an alternative for those who doesn't have an implamentation of VARIANT_XOR.
I'd love if somebody improve my "A_XOR_B" function by changing the name in "VARIANT_XOR" and to run the original VARIANT_XOR function (being optimized) if it is already in the PHP compilation, else run the custom XOR code.

<?php
function a_xor_b($a=0, $b=0) {
return ( (
$a!=$b) && ($a||$b) ) ? TRUE : FALSE ;
}
?>

If using this function, make sure you use the same type for arguments ;-)

Here is a sample code using it:

<?php
if ( a_xor_b(strlen($column1)>0,strlen($column2)>0) ) {
$add_and='';
}
if ( !
a_xor_b(strlen($column1)>0,strlen($column2)>0 ) && strlen($column1)>0 ) {
$add_and=' and ';
}
$some_sql_filter=$query_str.' having '.$column1.$add_and.$column2;
?>

The use of VARIANT_XOR was identical.

@PHP TEAM: the VARIANT set is so great :-)
up
-1
tinelbarb at yahoo dot com
13 years ago
I've been using a lot the VARIANT_XOR function (all the VARIANT functions ar cool) and I was faceing the problem that some custom copilation of PHP, especially LAMP packs, doesn't have the VARANT functions included, so the scripts halts.
I had to find an alternative for those who doesn't have an implamentation of VARIANT_XOR.
I'd love if somebody improve my "A_XOR_B" function by changing the name in "VARIANT_XOR" and to run the original VARIANT_XOR function (being optimized) if it is already in the PHP compilation, else run the custom XOR code.

<?php
function a_xor_b($a=0, $b=0) {
return ( (
$a!=$b) && ($a||$b) ) ? TRUE : FALSE ;
}
?>

If using this function, make sure you use the same type for arguments ;-)

Here is a sample code using it:

<?php
if ( a_xor_b(strlen($column1)>0,strlen($column2)>0) ) {
$add_and='';
}
if ( !
a_xor_b(strlen($column1)>0,strlen($column2)>0 ) && strlen($column1)>0 ) {
$add_and=' and ';
}
$some_sql_filter=$query_str.' having '.$column1.$add_and.$column2;
?>

The use of VARIANT_XOR was identical.

@PHP TEAM: the VARIANT set is so great :-)
up
-1
tinelbarb at yahoo dot com dot RE-MO-VE dot ME
13 years ago
I've been using a lot the VARIANT_XOR function (all the VARIANT functions ar cool) and I was faceing the problem that some custom copilation of PHP, especially LAMP packs, doesn't have the VARANT functions included, so the scripts halts.
I had to find an alternative for those who doesn't have an implamentation of VARIANT_XOR.
I'd love if somebody improve my "A_XOR_B" function by changing the name in "VARIANT_XOR" and to run the original VARIANT_XOR function (being optimized) if it is already in the PHP compilation, else run the custom XOR code.

<?php
function a_xor_b($a=0, $b=0) {
return ( (
$a!=$b) && ($a||$b) ) ? TRUE : FALSE ;
}
?>

If using this function, make sure you use the same type for arguments ;-)

Here is a sample code using it:

<?php
if ( a_xor_b(strlen($column1)>0,strlen($column2)>0) ) {
$add_and='';
}
if ( !
a_xor_b(strlen($column1)>0,strlen($column2)>0 ) && strlen($column1)>0 ) {
$add_and=' and ';
}
$some_sql_filter=$query_str.' having '.$column1.$add_and.$column2;
?>

The use of VARIANT_XOR was identical.

@PHP TEAM: the VARIANT set is so great :-)
To Top