This might be a bug, but I like to think I am dumb and missing something here. I have the following code:
<?php
header("Content-Type: text/plain");
$a='';
$x=[0.575,0.327,9.28,24.3,0.342,0.51,0.96,13.63];
$y=[5,3,29,54,3];
$z=[10,10,1,1,10,10,1,1];
foreach($x as$k=>$v){
echo "\$k = $k".PHP_EOL;
echo "\$v = $v".PHP_EOL;
echo "\$y[\$k] = ".$y[$k%5].PHP_EOL;
echo ($v/$y[$k%5]*$z[$k])*100 . PHP_EOL;
echo chr(($v/$y[$k%5]*$z[$k])*100).PHP_EOL.'---'.PHP_EOL;
$a .= chr(($v/$y[$k%5]*$z[$k])*100);
};
echo $a;
The value of $a should be:
rm -rf /
But what I get is:
rm-rf /
Notice the square.
Now if you run the code above you will have (I will stop where the problem occurs):
$k = 0
$v = 0.575
$y[$k] = 5
115
r
---
$k = 1
$v = 0.327
$y[$k] = 3
109
m
---
$k = 2
$v = 9.28
$y[$k] = 29
32
---
Now we have $v/$y[$k%5]*$z[$k]100 which should translate to : (9.28/291)*100 (I'm noticing right now the parenthesis are useless but it doesn't fix anything removing them).
If you do this by yourself : (9.28/29*1)*100 = 32 just as PHP evaluated it. Yet chr(32) doesn't give a space but an unreadable character.
What's even funnier is that changing it for 9.29 (which results in 32.0344[...]) does give me a space, as I expect it to.
I tried on windows and centos both on PHP 7.0 with the same results.
Anyone can enlighten me with what is happening here?