Exemplo n.º 1
0
<?php

// throwable_error.php
try {
    function takesInt(int $x)
    {
        return true;
    }
    takesInt('not an int');
} catch (Exception $e) {
    echo 'Exception caught<br>';
} catch (Throwable $t) {
    echo 'Throwable caught<br>';
} finally {
    echo 'In finally<br>';
}
Exemplo n.º 2
0
    $result = takesInt($b);
    echo "Returned:<br>";
    var_dump($result);
});
safeRun("Passing a string", function () {
    $s = "1";
    $result = takesInt($s);
    echo "Returned:<br>";
    var_dump($result);
});
safeRun("Passing a string which in no way can be considered an int", function () {
    $s = "not an integer";
    $result = takesInt($s);
    echo "Returned:<br>";
    var_dump($result);
});
safeRun("Passing a PHP object", function () {
    $d = new DateTime();
    $result = takesInt($d);
    echo "Returned:<br>";
    var_dump($result);
});
class C
{
}
safeRun("Passing a bespoke object", function () {
    $o = new C();
    $result = takesInt($o);
    echo "Returned:<br>";
    var_dump($result);
});
Exemplo n.º 3
0
<?php

// intObject.php
require __DIR__ . "/safeRun.php";
class int
{
}
function takesInt(int $i)
{
    return $i;
}
safeRun("Passing an int (object)", function () {
    $i = new int();
    $result = takesInt($i);
    echo "Returned:<br>";
    var_dump($result);
});