Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong boolean behavior #4007

Closed
imsamurai opened this issue Oct 17, 2014 · 7 comments
Closed

Wrong boolean behavior #4007

imsamurai opened this issue Oct 17, 2014 · 7 comments

Comments

@imsamurai
Copy link

Test code is:

$x =(!(strtolower('no') === 'no'));
var_dump($x);

should be false, but got true on all 3.* versions. Pure php 5.* outputs false
Tests: https://travis-ci.org/imsamurai/hhvm-test

@MaideCa
Copy link
Contributor

MaideCa commented Oct 17, 2014

My local master tests agree, but 3v4l disagrees (http://3v4l.org/gZ3TP).

Local script/output:

maide@sonic ~/hhvm $ cat test.php 
<?php
$x = (!(strtolower('no') === 'no'));
var_dump($x);
$x = ((strtolower('no') === 'no'));
var_dump($x);

PHP

maide@sonic ~/hhvm $ php -f test.php 
bool(false)
bool(true)

HHVM

maide@sonic ~/hhvm $ hphp/hhvm/hhvm -f test.php 
bool(true)
bool(true)

@imsamurai
Copy link
Author

Yes it is strange that 3v4l is ok. I tested on 3 machines + travis - all results was wrong

@SiebelsTim
Copy link
Contributor

Seems somehow related to strto(lower|upper)

<?php
$x = ((strtolower("no") === "no"));
var_dump($x);
$x = (!(strtolower("no") === "no"));
var_dump($x);

var_dump(!(strtolower("no") === "no"));
var_dump(((strtolower("no") === "no")));

// Everything down below works
echo "\n";

$x = (("no" === "no"));
var_dump($x);
$x = (!("no" === "no"));
var_dump($x);

var_dump(!("no" === "no"));
var_dump((("no" === "no")));

echo "\n";

$no = "no";
$no2 = "no";
var_dump(!(++$no === ++$no2));
var_dump(((++$no === ++$no2)));

@imsamurai
Copy link
Author

no, strtolower works as expected, i add more tests

@imsamurai
Copy link
Author

I suppose problem somewhere in code translation/optimization

@JoelMarcey
Copy link
Contributor

Hmmm....

I am having trouble repoing this. At first I thought it might be a JIT vs. interp issue, but on master, both are returning false for the sample that @imsamurai provided in the initial post.

[joelm /tmp] hhvmb -v Eval.Jit=1 4007.php
bool(false)
[joelm /tmp] hhvmb -v Eval.Jit=0 4007.php
bool(false)

@SiebelsTim
Copy link
Contributor

I can't reproduce this anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants