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

syntax error, unexpected token “%”

Description

PHP accepts one percentage %, for modulo. The % operator requires 2 operands, one before, and one after. This is not the same as + and -, which can be used as unary operator.

Example

<?php

$a = 2 + % 3;

?>

Alternatives

  • Remove the superfluous percentage.