php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73770 Truth table errors
Submitted: 2016-12-17 09:12 UTC Modified: 2016-12-17 11:41 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: rjhdby@php.net Assigned:
Status: Open Package: COM related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rjhdby@php.net
New email:
PHP Version: OS:

 

 [2016-12-17 09:12 UTC] rjhdby@php.net
Description:
------------
---
From manual page: http://www.php.net/function.variant-imp
---

Truth table for bitwise implication is not correct.

Must be
If left is	If right is	then the result is
TRUE	TRUE	TRUE
TRUE	FALSE	TRUE   >> FALSE
TRUE	NULL	TRUE   >> FALSE
FALSE	TRUE	TRUE
FALSE	FALSE	TRUE
FALSE	NULL	TRUE
NULL	TRUE	TRUE
NULL	FALSE	NULL   >> TRUE
NULL	NULL	NULL   >> TRUE



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-17 11:41 UTC] requinix@php.net
-Package: Documentation problem +Package: COM related
 [2016-12-17 11:41 UTC] requinix@php.net
When I try

foreach ([true, false, null] as $i)
foreach ([true, false, null] as $j) {
  $v = variant_imp($i, $j);
  $v = (variant_get_type($v) == VT_NULL ? null : (int)$v);
  printf("variant_imp(%s, %s) = %s\n", json_encode($i), json_encode($j), json_encode($v));
}

I get

variant_imp(true, true) = -1
variant_imp(true, false) = 0
variant_imp(true, null) = null
variant_imp(false, true) = -1
variant_imp(false, false) = -1
variant_imp(false, null) = -1
variant_imp(null, true) = -1
variant_imp(null, false) = null
variant_imp(null, null) = null

true->false should be false ("true implies false" is wrong). true->null, null->false, and null->null should all be unknown.
 [2016-12-17 18:19 UTC] andrewgrom at rambler dot ru
The problem is more complex. It is bitwise operation.

$T = new VARIANT(255,VT_UI1);
$F = new VARIANT(0,VT_UI1);
$N = new VARIANT(VT_NULL,VT_UI1);

echo variant_imp($T, $F).PHP_EOL;
echo variant_imp($T, $T).PHP_EOL;
echo variant_imp($T, $N).PHP_EOL;
echo variant_imp($F, $F).PHP_EOL;
echo variant_imp($F, $T).PHP_EOL;
echo variant_imp($F, $N).PHP_EOL;
echo variant_imp($N, $F).PHP_EOL;
echo variant_imp($N, $T).PHP_EOL;
echo variant_imp($N, $N).PHP_EOL;

0
255
1  <--- Not null
255
255
255
254 <--- Not null. True in all bits except one
255 
255 <--- Totaly not null. True in all bits
 [2016-12-17 19:21 UTC] andrewgrom at rambler dot ru
My mistake in previsious comment.
You are right,
"true->false should be false ("true implies false" is wrong). true->null, null->false, and null->null should all be unknown."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 17:01:32 2024 UTC