Skip to content

php:eval

Evaluate arbitrary php code after bootstrapping Drupal (if available).

Examples

  • drush php:eval '$node = node_load(1); print $node->title;'. Loads node with nid 1 and then prints its title.
  • drush php:eval "file_unmanaged_copy(\'$HOME/Pictures/image.jpg\', \'public://image.jpg\');". Copies a file whose path is determined by an environment's variable. Use of double quotes so the variable $HOME gets replaced by its value.
  • drush php:eval "node_access_rebuild();". Rebuild node access permissions.

Arguments

  • code. PHP code

Options

  • --format[=FORMAT]. [default: var_export]

Aliases

  • eval
  • ev
  • php-eval

Legend

  • An argument or option with square brackets is optional.
  • Any default value is listed at end of arg/option description.
  • An ellipsis indicates that an argument accepts multiple values separated by a space.