Skip to content
Draft
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
3 changes: 3 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ PHP 8.5 INTERNALS UPGRADE NOTES
. zend_mm_refresh_key_child() must be called on any zend_mm_heap inherited
from the parent process after a fork().
. HASH_KEY_IS_* constants have been moved in the zend_hash_key_type enum.
. ZSTR_INIT_LITERAL(), zend_string_starts_with_literal(), and
zend_string_starts_with_literal_ci now support strings containing NUL
bytes. Passing non-literal char* is no longer supported.

- standard
. ext/standard/php_smart_string.h and ext/standard/php_smart_string_public.h
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ END_EXTERN_C()

#define ZSTR_ALLOCA_FREE(str, use_heap) free_alloca(str, use_heap)

#define ZSTR_INIT_LITERAL(s, persistent) (zend_string_init((s), strlen(s), (persistent)))
#define ZSTR_INIT_LITERAL(s, persistent) (zend_string_init(("" s), sizeof(s) - 1, (persistent)))

/*---*/

Expand Down Expand Up @@ -402,7 +402,7 @@ static zend_always_inline bool zend_string_starts_with(const zend_string *str, c
}

#define zend_string_starts_with_literal(str, prefix) \
zend_string_starts_with_cstr(str, prefix, strlen(prefix))
zend_string_starts_with_cstr(str, "" prefix, sizeof(prefix) - 1)

static zend_always_inline bool zend_string_starts_with_cstr_ci(const zend_string *str, const char *prefix, size_t prefix_length)
{
Expand All @@ -415,7 +415,7 @@ static zend_always_inline bool zend_string_starts_with_ci(const zend_string *str
}

#define zend_string_starts_with_literal_ci(str, prefix) \
zend_string_starts_with_cstr_ci(str, prefix, strlen(prefix))
zend_string_starts_with_cstr_ci(str, "" prefix, sizeof(prefix) - 1)

/*
* DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ zend_result dom_element_class_name_write(dom_object *obj, zval *newval)
zval *dom_get_prop_checked_offset(dom_object *obj, uint32_t offset, const char *name)
{
#if ZEND_DEBUG
zend_string *name_zstr = ZSTR_INIT_LITERAL(name, false);
zend_string *name_zstr = zend_string_init(name, strlen(name), false);
const zend_property_info *prop_info = zend_get_property_info(obj->std.ce, name_zstr, 0);
zend_string_release_ex(name_zstr, false);
ZEND_ASSERT(OBJ_PROP_TO_NUM(prop_info->offset) == offset);
Expand Down
7 changes: 7 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ static ZEND_FUNCTION(zend_test_zend_ini_str)
RETURN_STR(ZT_G(str_test));
}

static ZEND_FUNCTION(zend_test_zstr_init_literal)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_STR(ZSTR_INIT_LITERAL("foo\0bar", false));
}

static ZEND_FUNCTION(zend_test_is_string_marked_as_valid_utf8)
{
zend_string *str;
Expand Down
1 change: 1 addition & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ function zend_test_zend_ini_parse_quantity(string $str): int {}
function zend_test_zend_ini_parse_uquantity(string $str): int {}

function zend_test_zend_ini_str(): string {}
function zend_test_zstr_init_literal(): string {}

#ifdef ZEND_CHECK_STACK_LIMIT
function zend_test_zend_call_stack_get(): ?array {}
Expand Down
6 changes: 5 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions ext/zend_test/tests/zstr_init_literal.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
zstr_init_literal
--EXTENSIONS--
zend_test
--FILE--
<?php

var_dump(strlen(zend_test_zstr_init_literal()), bin2hex(zend_test_zstr_init_literal()));

?>
--EXPECT--
int(7)
string(14) "666f6f00626172"