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

Cannot use ‘final’ as constant modifier

Description

final is an option for methods, and it is not available for class constants and properties. It becomes a feature with class constants in PHP 8.0.

Example

<?php

class X {
	private static const A  = 1;
}

?>

Alternatives

  • Remove the option from the constant signature.

In more recent PHP versions, this error message is now :ref:cannot-use-the-%s-modifier-on-a-%s.