Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new "command" in PHP

Tags:

php

frameworks

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.

like image 592
Scott Avatar asked Apr 25 '26 03:04

Scott


2 Answers

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.

like image 122
Ignacio Vazquez-Abrams Avatar answered Apr 26 '26 17:04

Ignacio Vazquez-Abrams


throw is a keyword defined by PHP. There is no way, without modifying the PHP parser, to do what you're asking for.

like image 39
zneak Avatar answered Apr 26 '26 17:04

zneak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!