如何从命令行中执行类中的方法 [英] How do you execute a method in a class from the command line

查看:60
本文介绍了如何从命令行中执行类中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个PHP类,我想从命令行测试,并运行一个特定的方法。我相信这是一个基本的问题,但我缺少的东西从文档。我知道如何运行一个文件,显然 php -f 但不知道如何运行该文件是一个类,并执行给定的方法

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

推荐答案

这将工作:

php -r 'include "MyClass.php"; MyClass::foo();'

但我没有看到任何理由,除了测试

But I don't see any reasons do to that besides testing though.

这篇关于如何从命令行中执行类中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆