1

I want to invoke a method using bash script.

Code:

class ABC {
    public static function methodABC(){
        //My logic 
        echo "Done";
    }
}

That is my code when I am trying this using command line I am getting class fatal error.

php -r 'include "./src/ABC.php"; ABC::methodABC();'

Error:

PHP Fatal error:  Uncaught Error: Class 'ABC' not found in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1
1

1 Answer 1

1

Your code in ABC.php needs to start with <?php.

When executing code with -r, only the code passed as an argument doesn't need tags, not the code in the included file.

Sign up to request clarification or add additional context in comments.

2 Comments

inside my methodABC method i'm checking class_exists function but its not finding existed classes also
That's a different problem, that is not demonstrated with your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.