1--TEST--
2SPL: Countable::count() with wrong return types and exception.
3--FILE--
4<?php
5
6Class returnNull implements Countable {
7    function count(): int {
8        return 0;
9    }
10}
11
12Class returnString implements Countable {
13    #[ReturnTypeWillChange]
14    function count() {
15        return "hello";
16    }
17}
18
19Class returnObject implements Countable {
20    #[ReturnTypeWillChange]
21    function count() {
22        return new returnObject;
23    }
24}
25
26Class returnArray implements Countable {
27    #[ReturnTypeWillChange]
28    function count() {
29        return array(1,2,3);
30    }
31}
32
33Class throwException implements Countable {
34    #[ReturnTypeWillChange]
35    function count() {
36        throw new Exception('Thrown from count');
37    }
38}
39
40
41echo "Count returns null:\n";
42var_dump(count(new returnNull));
43
44echo "Count returns a string:\n";
45var_dump(count(new returnString));
46
47echo "Count returns an object:\n";
48var_dump(count(new returnObject));
49
50echo "Count returns an array:\n";
51var_dump(count(new returnArray));
52
53echo "Count throws an exception:\n";
54try {
55    echo count(new throwException);
56} catch (Exception $e) {
57    echo $e->getMessage();
58}
59
60?>
61--EXPECTF--
62Count returns null:
63int(0)
64Count returns a string:
65int(0)
66Count returns an object:
67
68Warning: Object of class returnObject could not be converted to int in %s on line %d
69int(1)
70Count returns an array:
71int(1)
72Count throws an exception:
73Thrown from count
74