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
. Add support for CURLINFO_CONN_ID in curl_getinfo() (thecaliskan)
. Add support for CURLINFO_QUEUE_TIME_T in curl_getinfo() (thecaliskan)

- Session:
. Fixed GH-19197: build broken with ZEND_STRL usage with memcpy
when implemented as macro. (David Carlier)

- Sockets:
. socket_set_option for multicast context throws a ValueError
when the socket family is not of AF_INET/AF_INET6 family. (David Carlier)
Expand Down
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ PHP 8.5 UPGRADE NOTES
. The clone language construct is now a function and supports reassigning
(readonly) properties during cloning via the new $withProperties parameter.
RFC: https://wiki.php.net/rfc/clone_with_v2
. Added Closure::getCurrent() to receive currently executing closure.

- Curl:
. curl_multi_get_handles() allows retrieving all CurlHandles current
Expand Down
64 changes: 64 additions & 0 deletions Zend/tests/closures/closure_get_current.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--TEST--
Closure::getCurrent()
--FILE--
<?php

$i = 1;

$c = function ($p) use (&$i) {
$self = Closure::getCurrent();
var_dump($p, $i);
$i++;
if ($p < 10) {
$self($p + 1);
}
};

$c(1);
var_dump($i);

function fail() {
Closure::getCurrent();
}

try {
fail();
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

function foo() {
var_dump(Closure::getCurrent());
}

try {
foo(...)();
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
int(1)
int(1)
int(2)
int(2)
int(3)
int(3)
int(4)
int(4)
int(5)
int(5)
int(6)
int(6)
int(7)
int(7)
int(8)
int(8)
int(9)
int(9)
int(10)
int(10)
int(11)
Current function is not a closure
Current function is not a closure
26 changes: 26 additions & 0 deletions Zend/tests/gh19053.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-19053: Incorrect properties_info_table for abstract properties
--FILE--
<?php

abstract class GP {
public abstract mixed $foo { get; }
}

class P extends GP {
public mixed $foo = 1;
}

class C extends P {
public mixed $foo { get => 2; }
}

$c = new C;
var_dump($c);

?>
--EXPECTF--
object(C)#%d (0) {
["foo"]=>
uninitialized(mixed)
}
17 changes: 17 additions & 0 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,23 @@ ZEND_METHOD(Closure, fromCallable)
}
/* }}} */

ZEND_METHOD(Closure, getCurrent)
{
ZEND_PARSE_PARAMETERS_NONE();

zend_execute_data *prev_ex = EX(prev_execute_data);

if (!prev_ex
|| !prev_ex->func
|| (prev_ex->func->common.fn_flags & (ZEND_ACC_CLOSURE|ZEND_ACC_FAKE_CLOSURE)) != ZEND_ACC_CLOSURE) {
zend_throw_error(NULL, "Current function is not a closure");
RETURN_THROWS();
}

zend_object *obj = ZEND_CLOSURE_OBJECT(prev_ex->func);
RETURN_OBJ_COPY(obj);
}

static ZEND_COLD zend_function *zend_closure_get_constructor(zend_object *object) /* {{{ */
{
zend_throw_error(NULL, "Instantiation of class Closure is not allowed");
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_closures.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public function bindTo(?object $newThis, object|string|null $newScope = "static"
public function call(object $newThis, mixed ...$args): mixed {}

public static function fromCallable(callable $callback): Closure {}

public static function getCurrent(): Closure {}
}
7 changes: 6 additions & 1 deletion Zend/zend_closures_arginfo.h

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

19 changes: 17 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1713,10 +1713,25 @@ void zend_build_properties_info_table(zend_class_entry *ce)
}
}

ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, zend_string *key, prop) {
if (prop->ce == ce && (prop->flags & ZEND_ACC_STATIC) == 0
&& !(prop->flags & ZEND_ACC_VIRTUAL)) {
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(!(prop->prototype->flags & ZEND_ACC_VIRTUAL) ? prop->prototype->offset : prop->offset);
const zend_property_info *root_prop = prop->prototype;
if (UNEXPECTED(root_prop->flags & ZEND_ACC_VIRTUAL)) {
/* Prototype is virtual, we need to manually hunt down the first backed property. */
root_prop = prop;
zend_class_entry *parent_ce;
while ((parent_ce = root_prop->ce->parent)) {
zend_property_info *parent_prop = zend_hash_find_ptr(&parent_ce->properties_info, key);
if (!parent_prop
|| parent_prop->prototype != prop->prototype
|| (parent_prop->flags & ZEND_ACC_VIRTUAL)) {
break;
}
root_prop = parent_prop;
}
}
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(root_prop->offset);
table[prop_table_offset] = prop;
}
} ZEND_HASH_FOREACH_END();
Expand Down