How to call a function within a PHP script from the command line

Asked

Viewed 505 times

2

I want to know if I can call a function inside a script from the command line, using for example:

$ php script.php minhaFunção() <argumento>

in the case, the function is not within a class (it is necessary to be?)

Below my code:

<?php

function dobro($valor) {
    $resultado = $valor + $valor;

    echo $resultado;
}

1 answer

2


To do this just use the parameter -r

Example:

php -r "require 'teste.php'; imprimeNome('Thon');"

Chamando função por linha de comando

Browser other questions tagged

You are not signed in. Login or sign up in order to post.