Skip to content

Commit 5d9cb20

Browse files
Add Stringable interface
1 parent 8ee0494 commit 5d9cb20

28 files changed

+79
-54
lines changed

Zend/tests/list_keyed_evaluation_order.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Observer objects for the Zend/tests/list_keyed_evaluation_order.* tests
44

5-
class Stringable
5+
class Stringcapable
66
{
77
private $name;
88
public function __construct(string $name) {

Zend/tests/list_keyed_evaluation_order.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ list() with keys, evaluation order
55

66
require_once "list_keyed_evaluation_order.inc";
77

8-
$a = new Stringable("A");
9-
$c = new Stringable("C");
8+
$a = new Stringcapable("A");
9+
$c = new Stringcapable("C");
1010

1111
$e = new IndexableRetrievable("E", new Indexable(["A" => "value for offset A", "C" => "value for offset C"]));
1212

Zend/tests/list_keyed_evaluation_order_nested.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ list() with keys, evaluation order: nested
55

66
require_once "list_keyed_evaluation_order.inc";
77

8-
$a = new Stringable("A");
9-
$c = new Stringable("C");
10-
$f = new Stringable("F");
11-
$g = new Stringable("G");
12-
$i = new Stringable("I");
8+
$a = new Stringcapable("A");
9+
$c = new Stringcapable("C");
10+
$f = new Stringcapable("F");
11+
$g = new Stringcapable("G");
12+
$i = new Stringcapable("I");
1313

1414
$k = new IndexableRetrievable("K", new Indexable([
1515
"A" => "offset value for A",

Zend/tests/type_declarations/scalar_basic.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $functions = [
1919
'bool' => function (bool $b) { return $b; }
2020
];
2121

22-
class Stringable {
22+
class Stringcapable {
2323
public function __toString() {
2424
return "foobar";
2525
}
@@ -40,7 +40,7 @@ $values = [
4040
NULL,
4141
[],
4242
new StdClass,
43-
new Stringable,
43+
new Stringcapable,
4444
fopen("data:text/plain,foobar", "r")
4545
];
4646

@@ -106,7 +106,7 @@ int(0)
106106
}
107107
*** Caught Argument 1 passed to {closure}() must be of the type int, object given, called in %s on line %d
108108

109-
*** Trying object(Stringable)#%s (0) {
109+
*** Trying object(Stringcapable)#%s (0) {
110110
}
111111
*** Caught Argument 1 passed to {closure}() must be of the type int, object given, called in %s on line %d
112112

@@ -160,7 +160,7 @@ float(0)
160160
}
161161
*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d
162162

163-
*** Trying object(Stringable)#%s (0) {
163+
*** Trying object(Stringcapable)#%s (0) {
164164
}
165165
*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d
166166

@@ -213,7 +213,7 @@ string(0) ""
213213
}
214214
*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d
215215

216-
*** Trying object(Stringable)#%s (0) {
216+
*** Trying object(Stringcapable)#%s (0) {
217217
}
218218
string(6) "foobar"
219219

@@ -266,7 +266,7 @@ bool(false)
266266
}
267267
*** Caught Argument 1 passed to {closure}() must be of the type bool, object given, called in %s on line %d
268268

269-
*** Trying object(Stringable)#%s (0) {
269+
*** Trying object(Stringcapable)#%s (0) {
270270
}
271271
*** Caught Argument 1 passed to {closure}() must be of the type bool, object given, called in %s on line %d
272272

Zend/tests/type_declarations/scalar_return_basic.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $functions = [
2121
'bool' => function ($b): bool { return $b; }
2222
];
2323

24-
class Stringable {
24+
class Stringcapable {
2525
public function __toString() {
2626
return "foobar";
2727
}
@@ -42,7 +42,7 @@ $values = [
4242
NULL,
4343
[],
4444
new StdClass,
45-
new Stringable,
45+
new Stringcapable,
4646
fopen("data:text/plain,foobar", "r")
4747
];
4848

@@ -94,7 +94,7 @@ int(0)
9494
*** Trying object(stdClass)#6 (0) {
9595
}
9696
*** Caught Return value of {closure}() must be of the type int, object returned in %s on line %d
97-
*** Trying object(Stringable)#7 (0) {
97+
*** Trying object(Stringcapable)#7 (0) {
9898
}
9999
*** Caught Return value of {closure}() must be of the type int, object returned in %s on line %d
100100
*** Trying resource(5) of type (stream)
@@ -132,7 +132,7 @@ float(0)
132132
*** Trying object(stdClass)#6 (0) {
133133
}
134134
*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d
135-
*** Trying object(Stringable)#7 (0) {
135+
*** Trying object(Stringcapable)#7 (0) {
136136
}
137137
*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d
138138
*** Trying resource(5) of type (stream)
@@ -169,7 +169,7 @@ string(0) ""
169169
*** Trying object(stdClass)#6 (0) {
170170
}
171171
*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d
172-
*** Trying object(Stringable)#7 (0) {
172+
*** Trying object(Stringcapable)#7 (0) {
173173
}
174174
string(6) "foobar"
175175
*** Trying resource(5) of type (stream)
@@ -206,7 +206,7 @@ bool(false)
206206
*** Trying object(stdClass)#6 (0) {
207207
}
208208
*** Caught Return value of {closure}() must be of the type bool, object returned in %s on line %d
209-
*** Trying object(Stringable)#7 (0) {
209+
*** Trying object(Stringcapable)#7 (0) {
210210
}
211211
*** Caught Return value of {closure}() must be of the type bool, object returned in %s on line %d
212212
*** Trying resource(5) of type (stream)

Zend/tests/type_declarations/scalar_return_basic_64bit.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $functions = [
2121
'bool' => function ($b): bool { return $b; }
2222
];
2323

24-
class Stringable {
24+
class Stringcapable {
2525
public function __toString() {
2626
return "foobar";
2727
}
@@ -42,7 +42,7 @@ $values = [
4242
NULL,
4343
[],
4444
new StdClass,
45-
new Stringable,
45+
new Stringcapable,
4646
fopen("data:text/plain,foobar", "r")
4747
];
4848

@@ -94,7 +94,7 @@ int(0)
9494
*** Trying object(stdClass)#6 (0) {
9595
}
9696
*** Caught Return value of {closure}() must be of the type int, object returned in %s on line %d
97-
*** Trying object(Stringable)#7 (0) {
97+
*** Trying object(Stringcapable)#7 (0) {
9898
}
9999
*** Caught Return value of {closure}() must be of the type int, object returned in %s on line %d
100100
*** Trying resource(5) of type (stream)
@@ -132,7 +132,7 @@ float(0)
132132
*** Trying object(stdClass)#6 (0) {
133133
}
134134
*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d
135-
*** Trying object(Stringable)#7 (0) {
135+
*** Trying object(Stringcapable)#7 (0) {
136136
}
137137
*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d
138138
*** Trying resource(5) of type (stream)
@@ -169,7 +169,7 @@ string(0) ""
169169
*** Trying object(stdClass)#6 (0) {
170170
}
171171
*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d
172-
*** Trying object(Stringable)#7 (0) {
172+
*** Trying object(Stringcapable)#7 (0) {
173173
}
174174
string(6) "foobar"
175175
*** Trying resource(5) of type (stream)
@@ -206,7 +206,7 @@ bool(false)
206206
*** Trying object(stdClass)#6 (0) {
207207
}
208208
*** Caught Return value of {closure}() must be of the type bool, object returned in %s on line %d
209-
*** Trying object(Stringable)#7 (0) {
209+
*** Trying object(Stringcapable)#7 (0) {
210210
}
211211
*** Caught Return value of {closure}() must be of the type bool, object returned in %s on line %d
212212
*** Trying resource(5) of type (stream)

Zend/tests/type_declarations/scalar_strict.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $functions = [
1313
'bool' => function (bool $b) { return $b; }
1414
];
1515

16-
class Stringable {
16+
class Stringcapable {
1717
public function __toString() {
1818
return "foobar";
1919
}
@@ -34,7 +34,7 @@ $values = [
3434
NULL,
3535
[],
3636
new StdClass,
37-
new Stringable,
37+
new Stringcapable,
3838
fopen("data:text/plain,foobar", "r")
3939
];
4040

@@ -100,7 +100,7 @@ int(2147483647)
100100
}
101101
*** Caught Argument 1 passed to {closure}() must be of the type int, object given, called in %s on line %d
102102

103-
*** Trying object(Stringable)#6 (0) {
103+
*** Trying object(Stringcapable)#6 (0) {
104104
}
105105
*** Caught Argument 1 passed to {closure}() must be of the type int, object given, called in %s on line %d
106106

@@ -153,7 +153,7 @@ float(NAN)
153153
}
154154
*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d
155155

156-
*** Trying object(Stringable)#6 (0) {
156+
*** Trying object(Stringcapable)#6 (0) {
157157
}
158158
*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d
159159

@@ -206,7 +206,7 @@ string(0) ""
206206
}
207207
*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d
208208

209-
*** Trying object(Stringable)#6 (0) {
209+
*** Trying object(Stringcapable)#6 (0) {
210210
}
211211
*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d
212212

@@ -259,7 +259,7 @@ bool(false)
259259
}
260260
*** Caught Argument 1 passed to {closure}() must be of the type bool, object given, called in %s on line %d
261261

262-
*** Trying object(Stringable)#6 (0) {
262+
*** Trying object(Stringcapable)#6 (0) {
263263
}
264264
*** Caught Argument 1 passed to {closure}() must be of the type bool, object given, called in %s on line %d
265265

Zend/tests/type_declarations/scalar_strict_64bit.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $functions = [
1313
'bool' => function (bool $b) { return $b; }
1414
];
1515

16-
class Stringable {
16+
class Stringcapable {
1717
public function __toString() {
1818
return "foobar";
1919
}
@@ -34,7 +34,7 @@ $values = [
3434
NULL,
3535
[],
3636
new StdClass,
37-
new Stringable,
37+
new Stringcapable,
3838
fopen("data:text/plain,foobar", "r")
3939
];
4040

@@ -100,7 +100,7 @@ int(9223372036854775807)
100100
}
101101
*** Caught Argument 1 passed to {closure}() must be of the type int, object given, called in %s on line %d
102102

103-
*** Trying object(Stringable)#6 (0) {
103+
*** Trying object(Stringcapable)#6 (0) {
104104
}
105105
*** Caught Argument 1 passed to {closure}() must be of the type int, object given, called in %s on line %d
106106

@@ -153,7 +153,7 @@ float(NAN)
153153
}
154154
*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d
155155

156-
*** Trying object(Stringable)#6 (0) {
156+
*** Trying object(Stringcapable)#6 (0) {
157157
}
158158
*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d
159159

@@ -206,7 +206,7 @@ string(0) ""
206206
}
207207
*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d
208208

209-
*** Trying object(Stringable)#6 (0) {
209+
*** Trying object(Stringcapable)#6 (0) {
210210
}
211211
*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d
212212

@@ -259,7 +259,7 @@ bool(false)
259259
}
260260
*** Caught Argument 1 passed to {closure}() must be of the type bool, object given, called in %s on line %d
261261

262-
*** Trying object(Stringable)#6 (0) {
262+
*** Trying object(Stringcapable)#6 (0) {
263263
}
264264
*** Caught Argument 1 passed to {closure}() must be of the type bool, object given, called in %s on line %d
265265

Zend/zend_exceptions.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ static const zend_function_entry zend_funcs_throwable[] = {
763763
ZEND_ABSTRACT_ME(throwable, getTrace, arginfo_class_Throwable_getTrace)
764764
ZEND_ABSTRACT_ME(throwable, getPrevious, arginfo_class_Throwable_getPrevious)
765765
ZEND_ABSTRACT_ME(throwable, getTraceAsString, arginfo_class_Throwable_getTraceAsString)
766-
ZEND_ABSTRACT_ME(throwable, __toString, arginfo_class_Throwable___toString)
767766
ZEND_FE_END
768767
};
769768
/* }}} */
@@ -812,7 +811,7 @@ void zend_register_default_exception(void) /* {{{ */
812811
INIT_CLASS_ENTRY(ce, "Exception", default_exception_functions);
813812
zend_ce_exception = zend_register_internal_class_ex(&ce, NULL);
814813
zend_ce_exception->create_object = zend_default_exception_new;
815-
zend_class_implements(zend_ce_exception, 1, zend_ce_throwable);
814+
zend_class_implements(zend_ce_exception, 2, zend_ce_throwable, zend_ce_stringable);
816815

817816
zend_declare_property_string(zend_ce_exception, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED);
818817
zend_declare_property_string(zend_ce_exception, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE);
@@ -830,7 +829,7 @@ void zend_register_default_exception(void) /* {{{ */
830829
INIT_CLASS_ENTRY(ce, "Error", default_exception_functions);
831830
zend_ce_error = zend_register_internal_class_ex(&ce, NULL);
832831
zend_ce_error->create_object = zend_default_exception_new;
833-
zend_class_implements(zend_ce_error, 1, zend_ce_throwable);
832+
zend_class_implements(zend_ce_error, 2, zend_ce_throwable, zend_ce_stringable);
834833

835834
zend_declare_property_string(zend_ce_error, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED);
836835
zend_declare_property_string(zend_ce_error, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE);

Zend/zend_exceptions.stub.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
interface Throwable
3+
interface Throwable extends Stringable
44
{
55
/** @return string */
66
function getMessage();
@@ -22,9 +22,6 @@ function getPrevious();
2222

2323
/** @return string */
2424
function getTraceAsString();
25-
26-
/** @return string */
27-
function __toString();
2825
}
2926

3027
class Exception implements Throwable

Zend/zend_exceptions_arginfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ ZEND_END_ARG_INFO()
1515

1616
#define arginfo_class_Throwable_getTraceAsString arginfo_class_Throwable_getMessage
1717

18-
#define arginfo_class_Throwable___toString arginfo_class_Throwable_getMessage
19-
2018
#define arginfo_class_Exception___clone arginfo_class_Throwable_getMessage
2119

2220
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Exception___construct, 0, 0, 0)

0 commit comments

Comments
 (0)