ext/standard: Deprecate passing integers outside the interval [0, 255] to chr() (#19441)

RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_integers_outside_the_interval_0_255_to_chr
This commit is contained in:
Gina Peter Banyard 2025-08-14 20:48:48 +01:00 committed by GitHub
parent 6009b8a100
commit cab46b27b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 139 additions and 160 deletions

View file

@ -4147,17 +4147,19 @@ static zend_result zend_compile_func_defined(znode *result, zend_ast_list *args)
}
/* }}} */
static zend_result zend_compile_func_chr(znode *result, zend_ast_list *args) /* {{{ */
static zend_result zend_compile_func_chr(znode *result, const zend_ast_list *args) /* {{{ */
{
if (args->children == 1 &&
args->child[0]->kind == ZEND_AST_ZVAL &&
Z_TYPE_P(zend_ast_get_zval(args->child[0])) == IS_LONG) {
zend_long c = Z_LVAL_P(zend_ast_get_zval(args->child[0])) & 0xff;
zval *zint;
if (
args->children == 1
&& args->child[0]->kind == ZEND_AST_ZVAL
&& (zint = zend_ast_get_zval(args->child[0]))
&& Z_TYPE_P(zint) == IS_LONG
&& Z_LVAL_P(zint) >= 0
&& Z_LVAL_P(zint) <= 255
) {
result->op_type = IS_CONST;
ZVAL_CHAR(&result->u.constant, c);
ZVAL_CHAR(&result->u.constant, Z_LVAL_P(zint));
return SUCCESS;
} else {
return FAILURE;

View file

@ -9,10 +9,10 @@ $bad_webp = __DIR__ . "/gh16232.webp";
copy($good_webp, $bad_webp);
var_dump(imagecreatefromwbmp($bad_webp));
$data = file_get_contents($bad_webp);
$data[3] = chr(-1);
$data[3] = chr(255);
file_put_contents($bad_webp, $data);
var_dump(imagecreatefromwbmp($bad_webp));
$data[3] = chr(1000);
$data[3] = chr(232);
file_put_contents($bad_webp, $data);
var_dump(imagecreatefromwbmp($bad_webp));
unlink($bad_webp);

View file

@ -2665,6 +2665,12 @@ PHP_FUNCTION(chr)
Z_PARAM_LONG(c)
ZEND_PARSE_PARAMETERS_END();
if (UNEXPECTED(c < 0 || c > 255)) {
php_error_docref(NULL, E_DEPRECATED,
"Providing a value not in-between 0 and 255 is deprecated,"
" this is because a byte value must be in the [0, 255] interval."
" The value used will be constrained using %% 256");
}
c &= 0xff;
RETURN_CHAR(c);
}

View file

@ -8,7 +8,7 @@ Test array_filter() function : usage variations - built-in functions as 'callbac
echo "*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***\n";
$input = array(0, 1, -1, 10, 100, 1000);
$input = array(0, 1, 10, 100);
// using built-in function 'is_int' as 'callback'
var_dump( array_filter($input, 'is_int') );
@ -34,33 +34,25 @@ echo "Done"
?>
--EXPECT--
*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***
array(6) {
array(4) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(-1)
[3]=>
int(10)
[4]=>
[3]=>
int(100)
[5]=>
int(1000)
}
array(6) {
array(4) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(-1)
[3]=>
int(10)
[4]=>
[3]=>
int(100)
[5]=>
int(1000)
}
array_filter(): Argument #2 ($callback) must be a valid callback or null, function "echo" not found or invalid function name
array_filter(): Argument #2 ($callback) must be a valid callback or null, function "isset" not found or invalid function name

View file

@ -0,0 +1,15 @@
--TEST--
chr() with out of range values
--FILE--
<?php
var_dump("\xFF" == chr(-1));
var_dump("\0" == chr(256));
?>
--EXPECTF--
Deprecated: chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value must be in the [0, 255] interval. The value used will be constrained using % 256 in %s on line 3
bool(true)
Deprecated: chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value must be in the [0, 255] interval. The value used will be constrained using % 256 in %s on line 4
bool(true)

View file

@ -5,36 +5,17 @@ Test chr() function : usage variations - test values for $ascii argument
echo "*** Testing chr() function: with unexpected inputs for 'ascii' argument ***\n";
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
$inputs = [
0,
1,
255,
256,
// float values
/*5*/ 10.5,
-20.5,
1.1234e6,
// boolean values
/*11*/ true,
10.5,
// bool values
true,
false,
TRUE,
FALSE,
);
];
// loop through with each element of the $inputs array to test chr() function
$count = 1;
@ -44,8 +25,6 @@ foreach($inputs as $input) {
$count ++;
}
fclose($file_handle); //closing the file handle
?>
--EXPECTF--
*** Testing chr() function: with unexpected inputs for 'ascii' argument ***
@ -56,22 +35,10 @@ string(2) "01"
-- Iteration 3 --
string(2) "ff"
-- Iteration 4 --
string(2) "00"
-- Iteration 5 --
Deprecated: Implicit conversion from float 10.5 to int loses precision in %s on line %d
string(2) "0a"
-- Iteration 5 --
string(2) "01"
-- Iteration 6 --
Deprecated: Implicit conversion from float -20.5 to int loses precision in %s on line %d
string(2) "ec"
-- Iteration 7 --
string(2) "48"
-- Iteration 8 --
string(2) "01"
-- Iteration 9 --
string(2) "00"
-- Iteration 10 --
string(2) "01"
-- Iteration 11 --
string(2) "00"

View file

@ -12,7 +12,7 @@ precision=14
echo "\n*** Testing str_replace() with various subjects ***";
$subject = "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE\000
\x000\x5ACD\0abcd \xXYZ\tabcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)";
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)";
/* needles in an array to be compared in the string $string */
$search_str = array (
@ -48,7 +48,7 @@ $search_str = array (
'b',
'\t',
"\t",
chr(128).chr(234).chr(65).chr(255).chr(256),
chr(128).chr(234).chr(65).chr(255).chr(0),
$subject
);
@ -65,233 +65,233 @@ for( $i = 0; $i < count($search_str); $i++ ) {
*** Testing str_replace() with various subjects ***
--- Iteration 0 ---
-- String after replacing the search value is => --
string(181) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(179) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!FOUND
?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '2' times
--- Iteration 1 ---
-- String after replacing the search value is => --
string(181) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(179) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!FOUND
?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '2' times
--- Iteration 2 ---
-- String after replacing the search value is => --
string(186) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(184) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: FOUND
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 3 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 4 ---
-- String after replacing the search value is => --
string(186) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(184) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $FOUND: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 5 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 6 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 7 ---
-- String after replacing the search value is => --
string(193) "Hello, world,0120333.3445FOUND67 NULL TRUE FALSE%0
string(191) "Hello, world,0120333.3445FOUND67 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 8 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 9 ---
-- String after replacing the search value is => --
string(197) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0FOUND \xXYZ FOUND $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '2' times
--- Iteration 10 ---
-- String after replacing the search value is => --
string(197) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xFOUND abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 11 ---
-- String after replacing the search value is => --
string(196) "Hello, world,0120333.3445-1.234567 FOUND TRUE FALSE%0
string(194) "Hello, world,0120333.3445-1.234567 FOUND TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 12 ---
-- String after replacing the search value is => --
string(211) "Hello, world,FOUND12FOUND333.3445-1.234567 NULL TRUE FALSE%0
string(213) "Hello, world,FOUND12FOUND333.3445-1.234567 NULL TRUE FALSE%0
%0FOUNDZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(256)"
-- search string has found '4' times
?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(FOUND)"
-- search string has found '5' times
--- Iteration 13 ---
-- String after replacing the search value is => --
string(211) "Hello, world,FOUND12FOUND333.3445-1.234567 NULL TRUE FALSE%0
string(213) "Hello, world,FOUND12FOUND333.3445-1.234567 NULL TRUE FALSE%0
%0FOUNDZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(256)"
-- search string has found '4' times
?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(FOUND)"
-- search string has found '5' times
--- Iteration 14 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 15 ---
-- String after replacing the search value is => --
string(335) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE%0
string(333) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE%0
FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUND%00ZCD%0abcdFOUND\xXYZ abcdFOUND$$@#%^&*!~,.:;?:FOUND!!Hello,FOUNDWorld
FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '35' times
--- Iteration 16 ---
-- String after replacing the search value is => --
string(207) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSEFOUND
string(205) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSEFOUND
FOUND0ZCDFOUNDabcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '3' times
--- Iteration 17 ---
-- String after replacing the search value is => --
string(198) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(196) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
FOUNDZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 18 ---
-- String after replacing the search value is => --
string(198) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(196) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00FOUNDD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 19 ---
-- String after replacing the search value is => --
string(198) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(196) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
FOUNDZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 20 ---
-- String after replacing the search value is => --
string(198) "Hello, world,0120333FOUND445-1.234567 NULL TRUE FALSE%0
string(196) "Hello, world,0120333FOUND445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 21 ---
-- String after replacing the search value is => --
string(207) "Hello, world,0FOUND20333.3445-FOUND.234567 NULL TRUE FALSE%0
string(205) "Hello, world,0FOUND20333.3445-FOUND.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '3' times
--- Iteration 22 ---
-- String after replacing the search value is => --
string(196) "Hello, world,0120333.3445-1.234567 NULL FOUND FALSE%0
string(194) "Hello, world,0120333.3445-1.234567 NULL FOUND FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 23 ---
-- String after replacing the search value is => --
string(207) "Hello, world,0FOUND20333.3445-FOUND.234567 NULL TRUE FALSE%0
string(205) "Hello, world,0FOUND20333.3445-FOUND.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '3' times
--- Iteration 24 ---
-- String after replacing the search value is => --
string(207) "Hello, world,0FOUND20333.3445-FOUND.234567 NULL TRUE FALSE%0
string(205) "Hello, world,0FOUND20333.3445-FOUND.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '3' times
--- Iteration 25 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 26 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FOUND%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FOUND%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 27 ---
-- String after replacing the search value is => --
string(335) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE%0
string(333) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE%0
FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUND%00ZCD%0abcdFOUND\xXYZ abcdFOUND$$@#%^&*!~,.:;?:FOUND!!Hello,FOUNDWorld
FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '35' times
--- Iteration 28 ---
-- String after replacing the search value is => --
string(190) "Hello, world,0120333.3445-1.234567FOUNDNULL TRUE FALSE%0
string(188) "Hello, world,0120333.3445-1.234567FOUNDNULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 29 ---
-- String after replacing the search value is => --
string(203) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(201) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0aFOUNDcd \xXYZ aFOUNDcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '2' times
--- Iteration 30 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 31 ---
-- String after replacing the search value is => --
string(199) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(197) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZFOUNDabcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '1' times
--- Iteration 32 ---
-- String after replacing the search value is => --
string(195) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
string(193) "Hello, world,0120333.3445-1.234567 NULL TRUE FALSE%0
%00ZCD%0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(0)"
-- search string has found '0' times
--- Iteration 33 ---

View file

@ -9,7 +9,7 @@ precision = 12
echo "#### Basic and Possible operations ####";
/* creating an array of strings to be compared */
$arrays = array(
array("a", 'A', chr(128), chr(255), chr(256)),
array("a", 'A', chr(128), chr(255), chr(0)),
array("acc", "Acc", 'aC', "acCc", 'acd', "?acc", 'Acc!', "$!acc", ";acc"),
array("1", "0", 0, "-1", -1, "", TRUE, true, FALSE, "string"),
array(10.5, 1.5, 9.5, 11.5, 100.5, 10.5E1, -10.5, 10, 0.5)

View file

@ -9,7 +9,7 @@ precision = 12
echo "#### Basic and Possible operations ####";
/* creating an array of strings to be compared */
$arrays = array(
array("a", "A", 'a', 'A', chr(128), chr(255), chr(256)),
array("a", "A", 'a', 'A', chr(128), chr(255), chr(0)),
array("acc", "Acc", 'ac', "accc", 'acd', "?acc", 'acc!', "$!acc", ";acc"),
array("1", "0", 0, "-1", -1, "", TRUE, FALSE, "string"),
array(10.5, 1.5, 9.5, 11.5, 100.5, 10.5E1, -10.5, 10, 0.5)

View file

@ -36,7 +36,7 @@ $strings = array( "Hello, World",
"Hello, World\t",
"Hello, World\\",
" ",
chr(128).chr(234).chr(65).chr(255).chr(256),
chr(128).chr(234).chr(65).chr(255).chr(0),
"abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$
[]{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\

View file

@ -10,7 +10,7 @@ echo "*** Test strncasecmp() function: with binary inputs ***\n";
echo "\n-- Checking with all 256 characters given, in binary format --\n";
/* loop through to get all 256 character's equivalent binary value, and check working of strncasecmp() */
$count = 1;
for($ASCII = 0; $ASCII <= 255; $ASCII++) {
for($ASCII = 0; $ASCII < 255; $ASCII++) {
$str1 = decbin($ASCII); //ASCII value in binary form
$str2 = decbin( ord( chr($ASCII) ) ); //Getting equivalent ASCII value for the character in binary form
echo "-- Iteration $count --\n";
@ -21,7 +21,7 @@ for($ASCII = 0; $ASCII <= 255; $ASCII++) {
echo "\n-- Checking with out of character's range, given in binary format --\n";
$str1 = decbin(256);
$str2 = decbin( ord( chr(256) ));
$str2 = decbin( ord( chr(0) ));
var_dump( strncasecmp($str1, $str2, 8) ); //comparing all the 8-bits; expected: int(1)
echo "\n*** Done ***\n";
@ -795,9 +795,6 @@ int(0)
-- Iteration 255 --
int(0)
int(0)
-- Iteration 256 --
int(0)
int(0)
-- Checking with out of character's range, given in binary format --
int(1)

View file

@ -9,8 +9,8 @@ echo bin2hex( chr(128) ) ." => ";
var_dump( strpos($string, chr(128)) );
echo bin2hex( chr(255) ) ." => ";
var_dump( strpos($string, chr(255), 3) );
echo bin2hex( chr(256) ) ." => ";
var_dump( strpos($string, chr(256)) );
echo bin2hex( chr(0) ) ." => ";
var_dump( strpos($string, chr(0)) );
?>
DONE

View file

@ -9,8 +9,8 @@ echo bin2hex( chr(128) ) ." => ";
var_dump( bin2hex( strstr($string, chr(128) ) ) );
echo bin2hex( chr(255) ) ." => ";
var_dump( bin2hex( strstr($string, chr(255) ) ) );
echo bin2hex( chr(256) ) ." => ";
var_dump( bin2hex( strstr($string, chr(256) ) ) );
echo bin2hex( chr(0) ) ." => ";
var_dump( bin2hex( strstr($string, chr(0) ) ) );
?>
DONE

View file

@ -14,10 +14,10 @@ var_dump( substr_count("abcabcabcabcabc", "abca") );
var_dump( substr_count("abcabcabcabcabc", "abca", 2) );
echo "\n-- complex strings containing other than 7-bit chars --\n";
$str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255);
$str = chr(128).chr(129).chr(128).chr(0).chr(255).chr(254).chr(255);
var_dump(substr_count($str, chr(128)));
var_dump(substr_count($str, chr(255)));
var_dump(substr_count($str, chr(256)));
var_dump(substr_count($str, chr(0)));
echo "\n-- heredoc string --\n";
$string = <<<EOD

View file

@ -5,10 +5,10 @@ Test substr_count() function (variation - 2)
echo "\n*** Testing possible variations ***\n";
echo "\n-- complex strings containing other than 7-bit chars --\n";
$str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255);
$str = chr(128).chr(129).chr(128).chr(0).chr(255).chr(254).chr(255);
var_dump(substr_count($str, chr(128)));
var_dump(substr_count($str, chr(255)));
var_dump(substr_count($str, chr(256)));
var_dump(substr_count($str, chr(0)));
echo "\n-- heredoc string --\n";
$string = <<<EOD