Skip to content

Commit ad4d663

Browse files
committed
Promote warnings to exceptions in settype() function
1 parent 04deb53 commit ad4d663

File tree

6 files changed

+135
-285
lines changed

6 files changed

+135
-285
lines changed

Zend/tests/settype_resource.phpt

-389 Bytes
Binary file not shown.

ext/standard/tests/general_functions/gettype_settype_basic.phpt

Lines changed: 25 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ foreach ($types as $type) {
9393
$loop_count = 1;
9494
foreach ($values as $var) {
9595
echo "-- Iteration $loop_count --\n"; $loop_count ++;
96-
// set to new type
97-
var_dump( settype($var, $type) );
9896

99-
// dump the var
100-
var_dump( $var );
97+
try {
98+
// set to new type
99+
var_dump( settype($var, $type) );
101100

102-
// check the new type
103-
var_dump( gettype($var) );
101+
// dump the var
102+
var_dump( $var );
103+
104+
// check the new type
105+
var_dump( gettype($var) );
106+
} catch (ValueError $exception) {
107+
echo $exception->getMessage() . "\n";
108+
}
104109
}
105110
}
106111

@@ -539,94 +544,33 @@ string(7) "boolean"
539544

540545
-- Setting type of data to resource --
541546
-- Iteration 1 --
542-
2: settype(): Cannot convert to resource type
543-
bool(false)
544-
array(3) {
545-
[0]=>
546-
int(1)
547-
[1]=>
548-
int(2)
549-
[2]=>
550-
int(3)
551-
}
552-
string(5) "array"
547+
Cannot convert to resource type
553548
-- Iteration 2 --
554-
2: settype(): Cannot convert to resource type
555-
bool(false)
556-
string(14) "another string"
557-
string(6) "string"
549+
Cannot convert to resource type
558550
-- Iteration 3 --
559-
2: settype(): Cannot convert to resource type
560-
bool(false)
561-
array(3) {
562-
[0]=>
563-
int(2)
564-
[1]=>
565-
int(3)
566-
[2]=>
567-
int(4)
568-
}
569-
string(5) "array"
551+
Cannot convert to resource type
570552
-- Iteration 4 --
571-
2: settype(): Cannot convert to resource type
572-
bool(false)
573-
int(1)
574-
string(7) "integer"
553+
Cannot convert to resource type
575554
-- Iteration 5 --
576-
2: settype(): Cannot convert to resource type
577-
bool(false)
578-
int(-20)
579-
string(7) "integer"
555+
Cannot convert to resource type
580556
-- Iteration 6 --
581-
2: settype(): Cannot convert to resource type
582-
bool(false)
583-
float(2.54)
584-
string(6) "double"
557+
Cannot convert to resource type
585558
-- Iteration 7 --
586-
2: settype(): Cannot convert to resource type
587-
bool(false)
588-
float(-2.54)
589-
string(6) "double"
559+
Cannot convert to resource type
590560
-- Iteration 8 --
591-
2: settype(): Cannot convert to resource type
592-
bool(false)
593-
NULL
594-
string(4) "NULL"
561+
Cannot convert to resource type
595562
-- Iteration 9 --
596-
2: settype(): Cannot convert to resource type
597-
bool(false)
598-
bool(false)
599-
string(7) "boolean"
563+
Cannot convert to resource type
600564
-- Iteration 10 --
601-
2: settype(): Cannot convert to resource type
602-
bool(false)
603-
string(11) "some string"
604-
string(6) "string"
565+
Cannot convert to resource type
605566
-- Iteration 11 --
606-
2: settype(): Cannot convert to resource type
607-
bool(false)
608-
string(6) "string"
609-
string(6) "string"
567+
Cannot convert to resource type
610568
-- Iteration 12 --
611-
2: settype(): Cannot convert to resource type
612-
bool(false)
613-
resource(%d) of type (stream)
614-
string(8) "resource"
569+
Cannot convert to resource type
615570
-- Iteration 13 --
616-
2: settype(): Cannot convert to resource type
617-
bool(false)
618-
resource(%d) of type (stream)
619-
string(8) "resource"
571+
Cannot convert to resource type
620572
-- Iteration 14 --
621-
2: settype(): Cannot convert to resource type
622-
bool(false)
623-
object(point)#1 (2) {
624-
["x"]=>
625-
int(10)
626-
["y"]=>
627-
int(20)
628-
}
629-
string(6) "object"
573+
Cannot convert to resource type
630574

631575
-- Setting type of data to array --
632576
-- Iteration 1 --

ext/standard/tests/general_functions/gettype_settype_error.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ echo "**** Testing gettype() and settype() functions ****\n";
1616
echo "\n*** Testing settype(): error conditions ***\n";
1717

1818
// passing an invalid type to set
19-
var_dump( settype( $var, "unknown" ) );
19+
try {
20+
settype( $var, "unknown" );
21+
} catch (ValueError $exception) {
22+
echo $exception->getMessage() . "\n";
23+
}
2024

2125
echo "Done\n";
2226
?>
23-
--EXPECTF--
27+
--EXPECT--
2428
**** Testing gettype() and settype() functions ****
2529

2630
*** Testing settype(): error conditions ***
27-
28-
Warning: settype(): Invalid type in %s on line %d
29-
bool(false)
31+
Invalid type
3032
Done

0 commit comments

Comments
 (0)