Basically I have a PHP class that that I want to test from the commandline and run a certain method. I am sure this is a basic question, but I am missing something from the docs. I know how to run a file, obviously php -f
but not sure how to run that file which is a class and execute a given method
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Here's a neater example of Repox's code. This will only run de method when called from the commandline.
I would probably use call_user_func to avoid harcoding class or method names. Input should probably use some kinf of validation, though...
Result:
As Pekka already mentioned, you need to write a script that handles the execution of the specific method and then run it from your commandline.
test.php:
And in your commandline
This will work:
But I don't see any reasons do to that besides testing though.