Skip to content
Draft
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 Zend/tests/cast_to_string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ string(5) "Array"
string(0) ""
string(1) "1"
string(0) ""

Warning: Resource to string conversion in %s on line %d
string(%d) "Resource id #%d"
string(2) "10"
Done
42 changes: 42 additions & 0 deletions Zend/tests/operator_unsupported_types.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ No error for [] . []
Warning: Array to string conversion
Object of class stdClass could not be converted to string
Warning: Array to string conversion
Warning: Resource to string conversion
No error for [] . STDOUT
Warning: Array to string conversion
No error for [] . "foo"
Expand All @@ -1056,13 +1057,19 @@ Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Warning: Array to string conversion
Warning: Resource to string conversion
No error for STDOUT . []
Warning: Resource to string conversion
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
Warning: Resource to string conversion
No error for STDOUT . STDOUT
Warning: Resource to string conversion
No error for STDOUT . "foo"
Warning: Array to string conversion
No error for "foo" . []
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
No error for "foo" . STDOUT
No error for "foo" . "foo"
Warning: Array to string conversion
Expand Down Expand Up @@ -1107,19 +1114,33 @@ Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
No error for STDOUT . null
Warning: Resource to string conversion
No error for null . STDOUT
Warning: Resource to string conversion
No error for STDOUT . true
Warning: Resource to string conversion
No error for true . STDOUT
Warning: Resource to string conversion
No error for STDOUT . false
Warning: Resource to string conversion
No error for false . STDOUT
Warning: Resource to string conversion
No error for STDOUT . 2
Warning: Resource to string conversion
No error for 2 . STDOUT
Warning: Resource to string conversion
No error for STDOUT . 3.5
Warning: Resource to string conversion
No error for 3.5 . STDOUT
Warning: Resource to string conversion
No error for STDOUT . "123"
Warning: Resource to string conversion
No error for "123" . STDOUT
Warning: Resource to string conversion
No error for STDOUT . "123foo"
Warning: Resource to string conversion
No error for "123foo" . STDOUT
No error for "foo" . null
No error for null . "foo"
Expand Down Expand Up @@ -2001,21 +2022,28 @@ No error for [] .= []
Warning: Array to string conversion
Object of class stdClass could not be converted to string
Warning: Array to string conversion
Warning: Resource to string conversion
No error for [] .= STDOUT
Warning: Array to string conversion
No error for [] .= "foo"
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
Warning: Array to string conversion
No error for STDOUT .= []
Warning: Resource to string conversion
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
Warning: Resource to string conversion
No error for STDOUT .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= "foo"
Warning: Array to string conversion
No error for "foo" .= []
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
No error for "foo" .= STDOUT
No error for "foo" .= "foo"
Warning: Array to string conversion
Expand Down Expand Up @@ -2060,19 +2088,33 @@ Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Warning: Resource to string conversion
No error for STDOUT .= null
Warning: Resource to string conversion
No error for null .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= true
Warning: Resource to string conversion
No error for true .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= false
Warning: Resource to string conversion
No error for false .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= 2
Warning: Resource to string conversion
No error for 2 .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= 3.5
Warning: Resource to string conversion
No error for 3.5 .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= "123"
Warning: Resource to string conversion
No error for "123" .= STDOUT
Warning: Resource to string conversion
No error for STDOUT .= "123foo"
Warning: Resource to string conversion
No error for "123foo" .= STDOUT
No error for "foo" .= null
No error for null .= "foo"
Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,10 @@ static zend_always_inline zend_string* __zval_get_string_func(zval *op, bool try
case IS_TRUE:
return ZSTR_CHAR('1');
case IS_RESOURCE:
zend_error(E_WARNING, "Resource to string conversion");
if (try && UNEXPECTED(EG(exception))) {
return NULL;
}
return zend_strpprintf(0, "Resource id #" ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op));
case IS_LONG:
return zend_long_to_str(Z_LVAL_P(op));
Expand Down
4 changes: 4 additions & 0 deletions ext/standard/tests/array/array_combine_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ array(2) {
string(11) "Hello world"
}
-- Iteration 10 --

Warning: Resource to string conversion in %s on line %d
array(3) {
["Class A object"]=>
object(classA)#%d (0) {
Expand All @@ -157,6 +159,8 @@ array(3) {
resource(%d) of type (stream)
}
-- Iteration 11 --

Warning: Resource to string conversion in %s on line %d
array(8) {
["hello"]=>
string(5) "hello"
Expand Down
8 changes: 8 additions & 0 deletions ext/standard/tests/array/array_diff_variation8.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ array(3) {
string(11) "Hello world"
}
-- Iteration 8 --

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(3) {
["a"]=>
string(1) "1"
Expand All @@ -184,6 +188,10 @@ array(3) {
["c"]=>
string(1) "3"
}

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(5) {
[11]=>
object(classA)#%d (0) {
Expand Down
2 changes: 2 additions & 0 deletions ext/standard/tests/array/array_fill_keys_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ array(4) {

-- Testing array_fill_keys() function with mixed array --

Warning: Resource to string conversion in %s on line %d

Warning: Array to string conversion in %s on line %d
array(7) {
["Resource id #%d"]=>
Expand Down
24 changes: 24 additions & 0 deletions ext/standard/tests/array/array_intersect_assoc_variation7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,25 @@ array(1) {
string(11) "Hello world"
}
-- Iteration 10 --

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(2) {
[11]=>
object(classA)#%d (0) {
}
["resource"]=>
resource(%d) of type (stream)
}

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(2) {
[11]=>
object(classA)#%d (0) {
Expand All @@ -183,6 +195,10 @@ array(2) {
resource(%d) of type (stream)
}
-- Iteration 11 --

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(4) {
[222]=>
string(5) "fruit"
Expand All @@ -193,6 +209,14 @@ array(4) {
["heredoc"]=>
string(11) "Hello world"
}

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(4) {
[222]=>
string(5) "fruit"
Expand Down
24 changes: 24 additions & 0 deletions ext/standard/tests/array/array_intersect_assoc_variation8.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,25 @@ array(1) {
string(11) "Hello world"
}
-- Iteration 10 --

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(2) {
[11]=>
object(classA)#%d (0) {
}
["resource"]=>
resource(%d) of type (stream)
}

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(2) {
[11]=>
object(classA)#%d (0) {
Expand All @@ -183,6 +195,10 @@ array(2) {
resource(%d) of type (stream)
}
-- Iteration 11 --

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(4) {
["heredoc"]=>
string(11) "Hello world"
Expand All @@ -193,6 +209,14 @@ array(4) {
[222]=>
string(5) "fruit"
}

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d

Warning: Resource to string conversion in %s on line %d
array(4) {
["heredoc"]=>
string(11) "Hello world"
Expand Down
Loading
Loading