创建一个新的“命令”在 PHP 中
我见过一些 PHP 应用程序使用如下代码行:
throw new Exception(....);
如何制作其中之一?我想做某种“抛出”命令。那叫什么?
例如,我正在编写一个应用程序,我想让后端易于使用,所以当开发人员想要设置环境变量时我想使用它:
add environment("varname","value");
但我不知道如何制作其中之一。
I've seen some PHP applications use lines of code that are like this:
throw new Exception(....);
How do I make one of those? I want to make sort of 'throw' command. What is that called?
For example, I'm writing an application, and I want to make the backend easy to use, so I want to use this when a developer wants to set an environment variable:
add environment("varname","value");
But I have no idea how to make one of those.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
throw
是内置于语言中。做你想做的事需要修改 PHP 编译器或实现 DSL,两者都不是都是简单的任务。throw
is built into the language. Doing what you want would require either modifying the PHP compiler or implementing a DSL, neither of which are simple tasks.throw
是PHP定义的关键字。如果不修改 PHP 解析器,就无法完成您所要求的操作。throw
is a keyword defined by PHP. There is no way, without modifying the PHP parser, to do what you're asking for.我认为你最好使用某种对象来做你想做的事。像这样:
I think you're better just to use some sort of an object to do what you want. Like this: