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

Can only throw objects

Description

The throw keyword operates on exceptions, which are always objects. So, it is not possible to throw other types, such as integers, strings or arrays.

Example

<?php

throw 1;

?>

Alternatives

  • Use throw new Exception().
  • Use throw new Error().
  • Use throw $object, where $object contains an error or an exception.
  • Use throw ($object), where $object contains an error or an exception.