Let's say I have a private function addUser()
in function.php
that takes $username
as an input variable and does some stuff:
function addUser($username) {
//do some stuff
}
Now I want to call this function and pass the value $username, if possible with PHP CLI. I guess that won't work from outside function.php
since it's private, but how could I do this then?
You get your command line argumenst passed in a argv array:
This should work. Because you are basically executing all that code in between
'
s. And in that you can includefunction.php
and, should appropriately calladdUser()
.see phpdoc.
You can use $argv. $argv[0] = the filename, $argv[1] = first thing after filename.
I.e. php function.php "some arg" would be addUser("some arg");
This works for me!