当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Pass parameters to router's controller method

问题描述:

It was kind of hard for me to form this as a title. Basically what I have is a simple laravel-like router that saves allowed locations in an array. My question is if I could supply some arguements dynamically through that array's elements. I think I did even worse in the body of the question so let me just give a simple example:

class Example(){

public function display($bool){

if($bool){

echo 'hey';

}else{

echo 'bye';

}

}

}

Now if you wanna call this class' method from somewhere else with a variable

$var = 'display';

$example = new Example();

$example->$var(true);

And you get 'hey', but what if I can only control the $var = 'display' part, and the code below is beyond my control. Can I still pass a value to that method? Something like

$var = 'display(true)';

$example = new Example();

$example->$var;

网友答案:

Not without some epic string parsing.

More importantly, if you need this, something that you're doing is horribly wrong.

分享给朋友:
您可能感兴趣的文章:
随机阅读: