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

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 this case, the function is not inside a class (do I need to be?)

Below my code:

<?php

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

    echo $resultado;
}
    
asked by anonymous 11.08.2017 / 04:09

1 answer

2

To do this, simply use the -r

Example:

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

    
11.08.2017 / 04:36