Skip to content

php:eval

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

Examples

  • php:eval '$node = \Drupal ode\Entity\Node::load(1); print $node->getTitle();'
  • php:eval "\Drupal::service('file_system')->copy('$HOME/Pictures/image.jpg', 'public://image.jpg');"
  • php:eval "node_access_rebuild();"

Arguments

  • code. PHP code. If shell escaping gets too tedious, consider using the php:script command.

Options

  • --format=FORMAT. A format for printing the returned data [default: var_dump]

Global Options

  • -v|vv|vvv, --verbose. Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  • -y, --yes. Auto-accept the default for all user prompts. Equivalent to --no-interaction.
  • -l, --uri=URI. A base URL for building links and selecting a multi-site. Defaults to https://default.
  • To see all global options, run drush core:global-options.

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.