Skip to content

Commit 9190405

Browse files
committed
Merge branch 'PHP-8.6'
# Conflicts: # NEWS
2 parents 6d57acf + 642899f commit 9190405

24 files changed

Lines changed: 252 additions & 91 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Anonymous class name is not truncated in the abstract method list
3+
--FILE--
4+
<?php
5+
new class { abstract public $p { get; } };
6+
?>
7+
--EXPECTF--
8+
Fatal error: Class class@anonymous%0%s must implement 1 abstract method (class@anonymous%0%s::$p::get) in %s on line %d
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Anonymous class names are not truncated in runtime error messages
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public private(set) int $p = 0;
8+
private function f() {}
9+
}
10+
11+
class B {
12+
private function __destruct() {}
13+
}
14+
15+
$o = new class {
16+
public function __construct(public readonly int $ro = 1) {}
17+
private function priv() {}
18+
public function ret(): int { return "x"; }
19+
public function args($a) {}
20+
public function byRef(&$a) {}
21+
public function callPriv() { (new A)->f(); }
22+
public function setPrivateSet() { $a = new A; $a->p = 1; }
23+
public function destroy() { new B; }
24+
};
25+
26+
$v = new class extends ArrayObject {
27+
public int $virtual { get => 1; }
28+
};
29+
30+
foreach ([
31+
fn() => $o->priv(),
32+
fn() => $o->callPriv(),
33+
fn() => $o->setPrivateSet(),
34+
fn() => $o->destroy(),
35+
fn() => $o->ro = 2,
36+
fn() => $o->ret(),
37+
fn() => $o->args(),
38+
fn() => $v->__unserialize([0, [], ['virtual' => 2]]),
39+
] as $fn) {
40+
try {
41+
$fn();
42+
} catch (Throwable $e) {
43+
echo $e::class, ': ', $e->getMessage(), "\n";
44+
}
45+
}
46+
47+
$o->byRef(...new ArrayIterator([1]));
48+
49+
?>
50+
--EXPECTF--
51+
Error: Call to private method class@anonymous%0%s::priv() from global scope
52+
Error: Call to private method A::f() from scope class@anonymous%0%s
53+
Error: Cannot modify private(set) property A::$p from scope class@anonymous%0%s
54+
Error: Call to private B::__destruct() from scope class@anonymous%0%s
55+
Error: Cannot modify readonly property class@anonymous%0%s::$ro
56+
TypeError: class@anonymous%0%s::ret(): Return value must be of type int, string returned
57+
ArgumentCountError: Too few arguments to function class@anonymous%0%s::args(), 0 passed in %s on line %d and exactly 1 expected
58+
Error: Cannot unserialize value for virtual property ArrayObject@anonymous%0%s::$virtual
59+
60+
Warning: Cannot pass by-reference argument 1 of class@anonymous%0%s::byRef() by unpacking a Traversable, passing by-value instead in %s on line %d
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Anonymous class name is not truncated in method inheritance errors
3+
--FILE--
4+
<?php
5+
class A { public function f() {} }
6+
new class extends A { private function f() {} };
7+
?>
8+
--EXPECTF--
9+
Fatal error: Access level to A@anonymous%0%s::f() must be public (as in class A) in %s on line %d

‎Zend/tests/attributes/override/020.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ echo "Done";
1818

1919
?>
2020
--EXPECTF--
21-
Fatal error: I@anonymous::c() has #[\Override] attribute, but no matching parent method exists in %s on line %d
21+
Fatal error: I@anonymous%0%s::c() has #[\Override] attribute, but no matching parent method exists in %s on line %d

‎Zend/tests/object_types/return_type_in_class.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $three = new class extends Two {
1919
$three->a();
2020
?>
2121
--EXPECTF--
22-
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
22+
Fatal error: Uncaught TypeError: Two@anonymous%0%s::a(): Return value must be of type object, int returned in %s:%d
2323
Stack trace:
2424
#0 %s(%d): Two@anonymous->a()
2525
#1 {main}

‎Zend/tests/object_types/return_type_inheritance_in_class.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $three = new class extends Two {
1919
$three->a();
2020
?>
2121
--EXPECTF--
22-
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
22+
Fatal error: Uncaught TypeError: Two@anonymous%0%s::a(): Return value must be of type object, int returned in %s:%d
2323
Stack trace:
2424
#0 %s(%d): Two@anonymous->a()
2525
#1 {main}

‎Zend/tests/object_types/return_type_inheritance_in_interface.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $three = new class implements Two {
1919
$three->a();
2020
?>
2121
--EXPECTF--
22-
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
22+
Fatal error: Uncaught TypeError: Two@anonymous%0%s::a(): Return value must be of type object, int returned in %s:%d
2323
Stack trace:
2424
#0 %s(%d): Two@anonymous->a()
2525
#1 {main}

‎Zend/tests/readonly_classes/gh10377.phpt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ try {
3434
var_dump($anon->field);
3535

3636
?>
37-
--EXPECT--
37+
--EXPECTF--
3838
int(2)
39-
Error: Cannot modify readonly property class@anonymous::$field
39+
Error: Cannot modify readonly property class@anonymous%0%s::$field
4040
int(2)
4141
int(2)
4242
int(123)

‎Zend/tests/type_declarations/union_types/anonymous_class.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ try {
2727
?>
2828
--EXPECTF--
2929
TypeError: class@anonymous%0%s::testParam(): Argument #1 ($a) must be of type class@anonymous|string, null given, called in %s on line %d
30-
TypeError: class@anonymous::test(): Return value must be of type class@anonymous|string, stdClass returned
30+
TypeError: class@anonymous%0%s::test(): Return value must be of type class@anonymous|string, stdClass returned

‎Zend/zend_API.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ ZEND_API void object_properties_load(zend_object *object, const HashTable *prope
17881788

17891789
/* Mimic unserialize behaviour for virtual properties. */
17901790
if (UNEXPECTED(property_info->flags & ZEND_ACC_VIRTUAL)) {
1791-
zend_throw_error(NULL, "Cannot unserialize value for virtual property %s::$%s", ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(property_info->name));
1791+
zend_throw_error(NULL, "Cannot unserialize value for virtual property %pS::$%s", object->ce->name, zend_get_unmangled_property_name(property_info->name));
17921792
return;
17931793
}
17941794

0 commit comments

Comments
 (0)