Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ PHP NEWS
- MBstring:
. Updated Unicode data tables to Unicode 17.0. (Yuya Hamada)

- Standard:
. Passing strings which are not one byte long to ord() is now deprecated.
(Girgias)

- URI:
. Fixed bug GH-19780 (InvalidUrlException should check $errors argument).
(nielsdos)
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ PHP 8.5 UPGRADE NOTES
. Passing integers outside the interval [0, 255] to chr() is now deprecated.
This is because a byte can only hold a value within this interval.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_integers_outside_the_interval_0_255_to_chr
. Passing a string which is not a single byte to ord() is now deprecated,
this is indicative of a bug.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_string_which_are_not_one_byte_long_to_ord
. Relying locally predefined variable $http_response_header is deprecated.
Instead one should call the http_get_last_response_headers() function.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_the_http_response_header_predefined_variable
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/constants/class_constants_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ String interning during constants substitution
opcache.enable_cli=0
--FILE--
<?php
define ("A", "." . ord(26) . ".");
define ("A", "." . ord(2) . ".");
eval("class A {const a = A;}");
var_dump(A::a);
?>
Expand Down
Binary file modified Zend/tests/nullsafe_operator/013.phpt
Binary file not shown.
16 changes: 10 additions & 6 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4186,14 +4186,18 @@ static zend_result zend_compile_func_chr(znode *result, const zend_ast_list *arg
}
/* }}} */

static zend_result zend_compile_func_ord(znode *result, zend_ast_list *args) /* {{{ */
static zend_result zend_compile_func_ord(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_STRING) {

zval *str;
if (
args->children == 1
&& args->child[0]->kind == ZEND_AST_ZVAL
&& (str = zend_ast_get_zval(args->child[0]))
&& Z_TYPE_P(str) == IS_STRING
&& Z_STRLEN_P(str) == 1
) {
result->op_type = IS_CONST;
ZVAL_LONG(&result->u.constant, (unsigned char)Z_STRVAL_P(zend_ast_get_zval(args->child[0]))[0]);
ZVAL_LONG(&result->u.constant, (unsigned char)Z_STRVAL_P(str)[0]);
return SUCCESS;
} else {
return FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/gb18030_2022_encoding.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ readGB18030_2022_ConversionTable(__DIR__ . '/data/GB18030-2022MappingTableBMP.tx
findInvalidChars($toUnicode, $invalid, $truncated);

function notFourByteCode($gb) {
return ((ord($gb) < 0x81 || ord($gb) > 0x84) && (ord($gb) < 0x90 || ord($gb) > 0xE3)) ||
return ((ord($gb[0]) < 0x81 || ord($gb[0]) > 0x84) && (ord($gb[0]) < 0x90 || ord($gb[0]) > 0xE3)) ||
(strlen($gb) > 1 && (ord($gb[1]) < 0x30 || ord($gb[1]) > 0x39));
}

Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/gb18030_encoding.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ $gb18030_BMP_Mappings = [
findInvalidChars($toUnicode, $invalid, $truncated);

function notFourByteCode($gb) {
return ((ord($gb) < 0x81 || ord($gb) > 0x84) && (ord($gb) < 0x90 || ord($gb) > 0xE3)) ||
return ((ord($gb[0]) < 0x81 || ord($gb[0]) > 0x84) && (ord($gb[0]) < 0x90 || ord($gb[0]) > 0xE3)) ||
(strlen($gb) > 1 && (ord($gb[1]) < 0x30 || ord($gb[1]) > 0x39));
}

Expand Down
9 changes: 9 additions & 0 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,15 @@ PHP_FUNCTION(ord)
Z_PARAM_STR(str)
ZEND_PARSE_PARAMETERS_END();

if (UNEXPECTED(ZSTR_LEN(str) != 1)) {
if (ZSTR_LEN(str) == 0) {
php_error_docref(NULL, E_DEPRECATED,
"Providing an empty string is deprecated");
} else {
php_error_docref(NULL, E_DEPRECATED,
"Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead");
}
}
RETURN_LONG((unsigned char) ZSTR_VAL(str)[0]);
}
/* }}} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Test get_html_translation_table() function : basic functionality - HTML 5/Window
--FILE--
<?php

function so($a,$b) { return ord($a) - ord($b); }
function so($a,$b) { return ord($a[0]) - ord($b[0]); }

echo "*** Testing get_html_translation_table() : basic functionality - HTML 5/Windows-1251 ***\n";

Expand Down
2 changes: 0 additions & 2 deletions ext/standard/tests/strings/ord_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var_dump(ord("@"));
var_dump(ord("\n"));
var_dump(ord("\x0A"));
var_dump(ord("\xFF"));
var_dump(ord("Hello"));

// Make sure all valid ascii chars round trip
for ($i = 0; $i < 255; $i++) {
Expand All @@ -37,4 +36,3 @@ int(64)
int(10)
int(10)
int(255)
int(72)
15 changes: 15 additions & 0 deletions ext/standard/tests/strings/ord_not_1_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
ord() with values not one byte long
--FILE--
<?php

var_dump(ord(""));
var_dump(ord("Hello"));

?>
--EXPECTF--
Deprecated: ord(): Providing an empty string is deprecated in %s on line 3
int(0)

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in %s on line 4
int(72)