Dutch PHP Conference 2025 - Call For Papers

variant_xor

(PHP 5, PHP 7, PHP 8)

variant_xorPerforms a logical exclusion on two variants

Опис

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

Performs a logical exclusion.

Параметри

left

The left operand.

right

The right operand.

Зауваження:

Як і у всіх інших варіантних арифметичних функцій, параметри цієї функції можуть мати PHP-тип (ціле число, рядок, десятковий дріб, логічний або null) або бути примірником класу COM, VARIANT чи DOTNET. Типи, вбудовані в PHP, будуть перетворені у "варіанти" за правилами, описаними в конструкторі класу variant. В об'єктів COM і DOTNET значеннями "варіантів" будуть початкові значення властивостей цих об'єктів.

Варіантні арифметичні функції є надбудовами однойменних функцій бібліотеки COM. Докладніша інформація про ці функції є в документації до бібліотеки MSDN. Функції в PHP називаються дещо інакше, ніж в бібліотеці MDSN. Наприклад, variant_add() в PHP відповідає VarAdd() в MSDN.

Значення, що повертаються

Variant XOR Rules
If left is If right is then the result is
truetruefalse
truefalsetrue
falsetruetrue
falsefalsefalse
nullnullnull

Помилки/виключення

Throws a com_exception on failure.

Прогляньте також

  • variant_or() - Performs a logical disjunction on two variants
  • variant_and() - Performs a bitwise AND operation between two variants

add a note

User Contributed Notes 3 notes

up
1
tinelbarb at yahoo dot com
14 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
14 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
14 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