从命令行调用php类方法在脚本中的最佳实践


Best practice calling php class method in script from command line

我有一个基本的框架php脚本。我希望它包含一个类和一些方法。

   <?php
   class cName{
       public static function  funcName(){
           echo 'this is a test';
       }    
    }
   cName::funcName();
   ?>

如果我像这样从命令行调用这个文件

  php fileName.php

我得到正确的输出。

  this is a test

我的问题是,考虑到最佳实践,我是否应该这样构建文件,只调用文件并让文件调用方法。使用命令行参数调用这个方法会更好吗?如果是这样,你能解释一下我可能需要如何改变文件的结构,以及你建议从命令行调用file的格式吗?

很简单,

php /var/www/fileName.php
//    output
> this is a test

或者你可以直接转到文件运行目录

www> php fileName.pgp