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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Added first-class callable cache to share instances for the duration of the
request. (ilutov)
. It is now possible to use reference assign on WeakMap without the key
needing to be present beforehand. (nielsdos)

- Intl:
. Added IntlNumberRangeFormatter class to format an interval of two numbers
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ PHP 8.6 UPGRADE NOTES
2. New Features
========================================

- Core:
. It is now possible to use reference assign on WeakMap without the key
needing to be present beforehand.

- Intl:
. Added IntlNumberRangeFormatter class to format an interval of two numbers with a given skeleton, locale, IntlNumberRangeFormatter::COLLAPSE_AUTO, IntlNumberRangeFormatter::COLLAPSE_NONE, IntlNumberRangeFormatter::COLLAPSE_UNIT, IntlNumberRangeFormatter::COLLAPSE_ALL collapse and
IntlNumberRangeFormatter::IDENTITY_FALLBACK_SINGLE_VALUE, IntlNumberRangeFormatter::IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE, IntlNumberRangeFormatter::IDENTITY_FALLBACK_APPROXIMATELY and
Expand Down
25 changes: 25 additions & 0 deletions Zend/tests/lazy_objects/gh20085.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-20085 (Assertion failure when combining lazy object get_properties exception with foreach loop)
--FILE--
<?php
class C {
public int $a;
public function __construct() {
$this->a = 1;
}
}
$obj = new C;
$reflector = new ReflectionClass(C::class);
foreach ($obj as &$value) {
$obj = $reflector->newLazyGhost(function ($obj) {
throw new Error;
});
}
echo !obj;
?>
--EXPECTF--
Fatal error: Uncaught Error in %s:%d
Stack trace:
#0 %s(%d): {closure:%s:%d}(Object(C))
#1 {main}
thrown in %s on line %d
13 changes: 13 additions & 0 deletions Zend/tests/weakrefs/weakmap_by_ref_dimension_assign.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
By-ref assign of WeakMap dimension
--FILE--
<?php
$obj = new stdClass;
$map = new WeakMap;
$int = 0;
$map[$obj] =& $int;
$int++;
var_dump($map[$obj]);
?>
--EXPECT--
int(1)
3 changes: 2 additions & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -7307,7 +7307,7 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
while (1) {
if (UNEXPECTED(pos >= fe_ht->nNumUsed)) {
/* reached end of iteration */
ZEND_VM_C_GOTO(fe_fetch_w_exit);
ZEND_VM_C_GOTO(fe_fetch_w_exit_exc);
}
pos++;
value = &p->val;
Expand Down Expand Up @@ -7403,6 +7403,7 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(array));
ZEND_VM_C_LABEL(fe_fetch_w_exit_exc):
if (UNEXPECTED(EG(exception))) {
UNDEF_RESULT();
HANDLE_EXCEPTION();
Expand Down
6 changes: 4 additions & 2 deletions Zend/zend_vm_execute.h

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

23 changes: 15 additions & 8 deletions Zend/zend_weakrefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,25 @@ static zval *zend_weakmap_read_dimension(zend_object *object, zval *offset, int
zend_weakmap *wm = zend_weakmap_from(object);
zend_object *obj_addr = Z_OBJ_P(offset);
zval *zv = zend_hash_index_find(&wm->ht, zend_object_to_weakref_key(obj_addr));
if (zv == NULL) {
if (type != BP_VAR_IS) {
zend_throw_error(NULL,
"Object %s#%d not contained in WeakMap", ZSTR_VAL(obj_addr->ce->name), obj_addr->handle);
if (type == BP_VAR_W || type == BP_VAR_RW) {
if (zv == NULL) {
zval value;
zend_weakref_register(obj_addr, ZEND_WEAKREF_ENCODE(&wm->ht, ZEND_WEAKREF_TAG_MAP));
ZVAL_NULL(&value);
zv = zend_hash_index_add_new(&wm->ht, zend_object_to_weakref_key(obj_addr), &value);
}
ZVAL_MAKE_REF(zv);
} else {
if (zv == NULL) {
if (type != BP_VAR_IS) {
zend_throw_error(NULL,
"Object %s#%d not contained in WeakMap", ZSTR_VAL(obj_addr->ce->name), obj_addr->handle);
return NULL;
}
return NULL;
}
return NULL;
}

if (type == BP_VAR_W || type == BP_VAR_RW) {
ZVAL_MAKE_REF(zv);
}
return zv;
}

Expand Down
4 changes: 0 additions & 4 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2040,8 +2040,6 @@ PHP_METHOD(DOMDocument, relaxNGValidateSource)

#endif

#ifdef LIBXML_HTML_ENABLED

static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
{
char *source;
Expand Down Expand Up @@ -2234,8 +2232,6 @@ PHP_METHOD(DOMDocument, saveHTML)
}
/* }}} end dom_document_save_html */

#endif /* defined(LIBXML_HTML_ENABLED) */

/* {{{ Register extended class used to create base node type */
static void dom_document_register_node_class(INTERNAL_FUNCTION_PARAMETERS, bool modern)
{
Expand Down
12 changes: 0 additions & 12 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,7 @@ PHP_MINFO_FUNCTION(dom)
php_info_print_table_row(2, "DOM/XML", "enabled");
php_info_print_table_row(2, "DOM/XML API Version", DOM_API_VERSION);
php_info_print_table_row(2, "libxml Version", LIBXML_DOTTED_VERSION);
#ifdef LIBXML_HTML_ENABLED
php_info_print_table_row(2, "HTML Support", "enabled");
#endif
#ifdef LIBXML_XPATH_ENABLED
php_info_print_table_row(2, "XPath Support", "enabled");
#endif
Expand Down Expand Up @@ -2709,20 +2707,10 @@ xmlChar *php_dom_libxml_fix_file_path(xmlChar *path)

xmlDocPtr php_dom_create_html_doc(void)
{
#ifdef LIBXML_HTML_ENABLED
xmlDocPtr lxml_doc = htmlNewDocNoDtD(NULL, NULL);
if (EXPECTED(lxml_doc)) {
lxml_doc->dict = xmlDictCreate();
}
#else
/* If HTML support is not enabled, then htmlNewDocNoDtD() is not available.
* This code mimics the behaviour. */
xmlDocPtr lxml_doc = xmlNewDoc((const xmlChar *) "1.0");
if (EXPECTED(lxml_doc)) {
lxml_doc->type = XML_HTML_DOCUMENT_NODE;
lxml_doc->dict = xmlDictCreate();
}
#endif
return lxml_doc;
}

Expand Down
2 changes: 0 additions & 2 deletions ext/dom/php_dom.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ extern zend_module_entry dom_module_entry;
#include <libxml/xinclude.h>
#include <libxml/hash.h>
#include <libxml/c14n.h>
#ifdef LIBXML_HTML_ENABLED
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#endif
#ifdef LIBXML_XPATH_ENABLED
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
Expand Down
2 changes: 0 additions & 2 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ public function registerNodeClass(string $baseClass, ?string $extendedClass): tr
/** @tentative-return-type */
public function save(string $filename, int $options = 0): int|false {}

#ifdef LIBXML_HTML_ENABLED
/** @tentative-return-type */
public function loadHTML(string $source, int $options = 0): bool {}

Expand All @@ -1025,7 +1024,6 @@ public function saveHTML(?DOMNode $node = null): string|false {}

/** @tentative-return-type */
public function saveHTMLFile(string $filename): int|false {}
#endif

/** @tentative-return-type */
public function saveXML(?DOMNode $node = null, int $options = 0): string|false {}
Expand Down
18 changes: 3 additions & 15 deletions ext/dom/php_dom_arginfo.h

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

3 changes: 1 addition & 2 deletions ext/random/randomizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,7 @@ PHP_METHOD(Random_Randomizer, __serialize)
ZEND_PARSE_PARAMETERS_NONE();

array_init(return_value);
ZVAL_ARR(&t, zend_std_get_properties(&randomizer->std));
Z_TRY_ADDREF(t);
ZVAL_ARR(&t, zend_array_dup(zend_std_get_properties(&randomizer->std)));
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &t);
}
/* }}} */
Expand Down
18 changes: 18 additions & 0 deletions ext/random/tests/03_randomizer/methods/__serialize_indirects.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Random: Engine: __serialize() must not expose INDIRECTs
--FILE--
<?php

$randomizer = new Random\Randomizer(null);
var_dump($randomizer->__serialize());

?>
--EXPECT--
array(1) {
[0]=>
array(1) {
["engine"]=>
object(Random\Engine\Secure)#2 (0) {
}
}
}
35 changes: 9 additions & 26 deletions ext/spl/spl_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ static zend_result spl_heap_unserialize_internal_state(HashTable *state_ht, spl_
return SUCCESS;
}

PHP_METHOD(SplPriorityQueue, __serialize)
static void spl_heap_serialize_internal(INTERNAL_FUNCTION_PARAMETERS, bool is_pqueue)
{
spl_heap_object *intern = Z_SPLHEAP_P(ZEND_THIS);
zval props, state;
Expand All @@ -1185,14 +1185,18 @@ PHP_METHOD(SplPriorityQueue, __serialize)

array_init(return_value);

ZVAL_ARR(&props, zend_std_get_properties(&intern->std));
Z_TRY_ADDREF(props);
ZVAL_ARR(&props, zend_array_dup(zend_std_get_properties(&intern->std)));
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &props);

spl_heap_serialize_internal_state(&state, intern, true);
spl_heap_serialize_internal_state(&state, intern, is_pqueue);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &state);
}

PHP_METHOD(SplPriorityQueue, __serialize)
{
spl_heap_serialize_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}

PHP_METHOD(SplPriorityQueue, __unserialize)
{
HashTable *data;
Expand Down Expand Up @@ -1241,28 +1245,7 @@ PHP_METHOD(SplPriorityQueue, __unserialize)

PHP_METHOD(SplHeap, __serialize)
{
spl_heap_object *intern = Z_SPLHEAP_P(ZEND_THIS);
zval props, state;

ZEND_PARSE_PARAMETERS_NONE();

if (UNEXPECTED(spl_heap_consistency_validations(intern, false) != SUCCESS)) {
RETURN_THROWS();
}

if (intern->heap->flags & SPL_HEAP_WRITE_LOCKED) {
zend_throw_exception(spl_ce_RuntimeException, "Cannot serialize heap while it is being modified.", 0);
RETURN_THROWS();
}

array_init(return_value);

ZVAL_ARR(&props, zend_std_get_properties(&intern->std));
Z_TRY_ADDREF(props);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &props);

spl_heap_serialize_internal_state(&state, intern, false);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &state);
spl_heap_serialize_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}

PHP_METHOD(SplHeap, __unserialize)
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/tests/SplHeap_serialize_indexed_format.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ array(2) {
[0]=>
array(2) {
["flags"]=>
UNKNOWN:0
string(13) "user_property"
["heap_elements"]=>
UNKNOWN:0
string(13) "user_property"
}
[1]=>
array(2) {
Expand Down
Loading