Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Polymorphisme des exceptions

<?php

interface i {}

class myException extends Exception implements i {}

try {
    throw new myException();
} catch(i $i) {
    var_dump($i instanceof myException);
}

Les exceptions personnalisées sont comme n’importe quelle autre classe : elles peuvent implémenter des interfaces. Ensuite, cette interface peut être utilisée pour attraper l’exception, même si l’interface n’a rien à voir avec les exceptions. Et avec plusieurs interfaces sur la même exception, il est possible de les attraper de différentes manières.

See Also

PHP Features

Last updated: 11 October 2026