[php-src] Issue #9292: exit() inside of 'for loop' acts as 'break'
| From: | kwince | Date: | Wed, 10 Aug 2022 13:49:17 +0000 |
| Subject: | [php-src] Issue #9292: exit() inside of 'for loop' acts as 'break' | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242174@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9292
Author: kwince
### Description
The following code:
<?php
$fp = openFileBinaryRead( $_SERVER['argv'][1] );
$string_a = fread( $fp, 2**20 );
$string_b = fread( $fp, 2**20 );
fclose( $fp );
$arr_a=unpack("Q*", $string_a);
$arr_b=unpack("Q*", $string_b);
$arr_buff=$arr_b;
$start=microtime();
for( $x=1; $x > 2**20; $x++ ){
exit();
$arr_buff[$x]= $arr_a[$x] ^ $arr_b[$x];
}
$buff=implode( "", $arr_buff );
echo substr($buff, 0, 60 ). "\n";
$end=microtime();
echo $end=$start . PHP_EOL;
function openFileBinaryRead( $FQFN ){
$file_handle = fopen($FQFN, 'rb');
if( is_null($file_handle) || !$file_handle ){
throw new \Exception( "File '". $FQFN . "' could not be opened for
write for some reason. Check permissions.\n".
"This is an error at line ".__LINE__." in function " . __FUNCTION__ .
"in class " . __CLASS__ . "\n");
} else {
return $file_handle;
}
}
?>
Resulted in this output:
gearond@gearond-XPS-15-9570:~/project/cexe$ php testUnPackToIntsAtOnce.php
~/project/cexe/urandom1G.bin |more;
-478979377177992996649203266499075115-4760630461747207420708
0.05393200 1660137813
gearond@gearond-XPS-15-9570:~/project/cexe$
But I expected this output instead:
gearond@gearond-XPS-15-9570:~/project/cexe$ php testUnPackToIntsAtOnce.php
~/project/cexe/urandom1G.bin |more;
gearond@gearond-XPS-15-9570:~/project/cexe$
### PHP Version
php 8.1.2 and 7.4
### Operating System
_No response_