使用 exec 调用/调用 php 类中的方法

发布于 2024-12-15 06:46:35 字数 394 浏览 1 评论 0原文

在 php 中,假设 test.php 中有一个名为“test_class”的类,它有两个方法:method_1method_2

这是我的 test.php 文件:

    class test_class  
    { 
       function method_1
       { .......   }

       function method_2
       { .......   }

    }

现在,使用其他 php 文件中的“exec”命令,我只想运行 test_class 中的 method_1。

我想知道如何实现这一目标?

In php suppose there is a class named as 'test_class' in test.php with two methods: method_1 and method_2.

This is my test.php file:

    class test_class  
    { 
       function method_1
       { .......   }

       function method_2
       { .......   }

    }

Now, using the "exec" command from other php file, I want to run only the method_1 in the test_class.

I want to know how this can be achieved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倒带 2024-12-22 06:46:35

你可以这样做:

include_once 'test.php'; // correct path if needed
$test = new test_class();
// call method1
$test->method_1();

You can do this instead:

include_once 'test.php'; // correct path if needed
$test = new test_class();
// call method1
$test->method_1();
梦一生花开无言 2024-12-22 06:46:35

您读过手册吗?

exec 并不意味着调用方法,它用于:

exec — 执行外部程序

Have you read the manual?

exec isn't meant to call methods, it's used to:

exec — Execute an external program

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文