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 %s as array

Description

This error is emitted when the right operand of a list operation is not an array, but a scalar, with the exception of null.

Example

<?php

list($a, $b) = 'abc';

?>

Literal Examples

  • Cannot use string as array
  • Cannot use boolean as array
  • Cannot use integer as array
  • Cannot use float as array
  • Cannot use object as array

Alternatives

  • Convert the right operand to an array first.
  • Use a simple assignation, rather than list.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See destructuringNonArray