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 @@ -11,6 +11,10 @@ PHP NEWS
. Fixed bug GH-19780 (InvalidUrlException should check $errors argument).
(nielsdos)

- Windows:
. Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket).
(dktapps)

11 Sep 2025, PHP 8.5.0beta3

- Core:
Expand Down
6 changes: 5 additions & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,11 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return
}

cptr -= ZSTR_LEN(glue);
memcpy(cptr, ZSTR_VAL(glue), ZSTR_LEN(glue));
if (ZSTR_LEN(glue) == 1) {
*cptr = ZSTR_VAL(glue)[0];
} else {
memcpy(cptr, ZSTR_VAL(glue), ZSTR_LEN(glue));
}
}

free_alloca(strings, use_heap);
Expand Down
47 changes: 47 additions & 0 deletions ext/standard/tests/serialize/gh12265.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
GH-12265 (Cloning an object breaks serialization recursion) - __serialize variation
--FILE--
<?php

class A {
public function __construct(public B $x) {
}
}

class B {
public A $a;

public function __serialize()
{
return ['a' => new A($this)];
}
}

class C {
public B $b;

public function __construct() {
$this->b = new B;
}
}

$b = new B();
$sb = serialize($b);
$stb = serialize(new B);

printf("serialized original: %s\n", $sb);
printf("serialized temp : %s\n", $stb);

$c = new C;
$sc = serialize($c);
$stc = serialize(new C);

printf("serialized original: %s\n", $sc);
printf("serialized temp : %s\n", $stc);

?>
--EXPECT--
serialized original: O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:1;}}
serialized temp : O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:1;}}
serialized original: O:1:"C":1:{s:1:"b";O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:2;}}}
serialized temp : O:1:"C":1:{s:1:"b";O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:2;}}}
49 changes: 49 additions & 0 deletions ext/standard/tests/serialize/gh12265b.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
GH-12265 (Cloning an object breaks serialization recursion) - __sleep variation
--FILE--
<?php

class A {
public function __construct(public B $x) {
}
}

class B {
public A $a;

public function __sleep()
{
$this->a = new A($this);
return ['a'];
}
}

class C {
public B $b;

public function __construct() {
$this->b = new B;
}
}

$b = new B();
$sb = serialize($b);
$stb = serialize(new B);

printf("serialized original: %s\n", $sb);
printf("serialized temp : %s\n", $stb);

$c = new C;
$sc = serialize($c);
$stc = serialize(new C);

printf("serialized original: %s\n", $sc);
printf("serialized temp : %s\n", $stc);

?>
--EXPECTF--
Deprecated: The __sleep() serialization magic method has been deprecated. Implement __serialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
serialized original: O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:1;}}
serialized temp : O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:1;}}
serialized original: O:1:"C":1:{s:1:"b";O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:2;}}}
serialized temp : O:1:"C":1:{s:1:"b";O:1:"B":1:{s:1:"a";O:1:"A":1:{s:1:"x";r:2;}}}
5 changes: 4 additions & 1 deletion ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,10 @@ static inline zend_long php_add_var_hash(php_serialize_data_t data, zval *var, b
return 0;
} else if (!in_rcn_array
&& Z_REFCOUNT_P(var) == 1
&& (Z_OBJ_P(var)->properties == NULL || GC_REFCOUNT(Z_OBJ_P(var)->properties) == 1)) {
&& (Z_OBJ_P(var)->properties == NULL || GC_REFCOUNT(Z_OBJ_P(var)->properties) == 1)
/* __serialize and __sleep may arbitrarily increase the refcount */
&& Z_OBJCE_P(var)->__serialize == NULL
&& zend_hash_find_known_hash(&Z_OBJCE_P(var)->function_table, ZSTR_KNOWN(ZEND_STR_SLEEP)) == NULL) {
return 0;
}

Expand Down
17 changes: 11 additions & 6 deletions win32/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
/* build an array of handles for non-sockets */
for (i = 0; (uint32_t)i < max_fd; i++) {
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);
if (handles[n_handles] == INVALID_HANDLE_VALUE) {
int _type;
int _len = sizeof(_type);

if (getsockopt((SOCKET)i, SOL_SOCKET, SO_TYPE, (char*)&_type, &_len) == 0 || WSAGetLastError() != WSAENOTSOCK) {
/* socket */
if (SAFE_FD_ISSET(i, rfds)) {
FD_SET((uint32_t)i, &sock_read);
Expand All @@ -82,11 +84,14 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
sock_max_fd = i;
}
} else {
if (SAFE_FD_ISSET(i, rfds) && GetFileType(handles[n_handles]) == FILE_TYPE_PIPE) {
num_read_pipes++;
handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);
if (handles[n_handles] != INVALID_HANDLE_VALUE) {
if (SAFE_FD_ISSET(i, rfds) && GetFileType(handles[n_handles]) == FILE_TYPE_PIPE) {
num_read_pipes++;
}
handle_slot_to_fd[n_handles] = i;
n_handles++;
}
handle_slot_to_fd[n_handles] = i;
n_handles++;
}
}
}
Expand Down