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

Destructors cannot declare a return type

Description

There can be no return type for a destructor method. It is called while destroying an existing instance of an object, and the object won’t be available at the end.

Example

<?php

class X {
	function __destruct() : int {}
}

?>

Alternatives

  • Remove the return type of the method.