Creating a new "team" in PHP

I have seen some PHP applications use lines of code that look like this:

throw new Exception(....); 

How can I do one of them? I want to make the quit command. What is called?

For example, I am writing an application and I want to make the backend easy to use, so I want to use it when the developer wants to set the environment variable:

 add environment("varname","value"); 

But I have no idea how to make one of them.

+2
source share
3 answers

throw is built into the language . Doing what you want will require either a modification of the PHP compiler or a DSL implementation, none of which are simple tasks.

+5
source

throw is a keyword defined by PHP . There is no way, without changing the PHP parser, to do what you ask.

+3
source

I think you better just use some kind of object to do what you want. Like this:

 <?php class Environment { public $arr = array(); public function add($name, $value) { array_push($this->arr, array($name, $value)); } } $env = new Environment; $env->add('foo','bar'); print_r($env->arr); 
+1
source

All Articles