Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php-重试执行一行_Php_Variables_Line_Handler_Execute - Fatal编程技术网

Php-重试执行一行

Php-重试执行一行,php,variables,line,handler,execute,Php,Variables,Line,Handler,Execute,在解释我想做什么之前,以下是我的代码: set_error_handler(function($errno, $errstr) { if (strpos($errstr, 'Undefined variable: ') === 0) { // Get my var $words = explode(' ', $errstr); // Var is not declared before so "we create it" in g

在解释我想做什么之前,以下是我的代码:

set_error_handler(function($errno, $errstr)
{
    if (strpos($errstr, 'Undefined variable: ') === 0)
    {
        // Get my var
        $words = explode(' ', $errstr);

        // Var is not declared before so "we create it" in global (wizard astuce ;p)
        global $route, ${$words[2]};

        // I put a content to my var
        ${$words[2]} = array('tutu' => 'toto');

        // I don't display error
        return true;
    }
    return false;
}, E_NOTICE);

// I want to display "toto" without declared my var before
echo $News['tutu'].'<br/><br/>';
echo $News['tutu'].'<br/><br/>';
set\u error\u处理程序(函数($errno,$errstr)
{
if(strpos($errstr,'未定义变量:')==0)
{
//获取我的var
$words=explode(“”,$errstr);
//Var之前未声明,因此在全局(向导astuce;p)中“我们创建它”
全局$route,${$words[2]};
//我把一个内容放在我的var中
${$words[2]}=array('tutu'=>'toto');
//我不显示错误
返回true;
}
返回false;
},E_通知);
//我想显示“toto”而不在之前声明我的var
echo$News['tutu'].

; echo$News['tutu'].

所以…,第一次$News['tututu']不起作用,第二次效果很好

我想做的是重试$News['tututu']的第一次执行,或者获取var(['tutu'])的结尾,然后获取“toto”


如果我能避免使用“substr”、“open”等。。。这将是完美的。

这是错误处理程序的一些非常奇怪的用法。这会让你的代码变得更加复杂,让其他人都无法理解。哈哈,我知道。事实是,一切都是虚无缥缈的!如果您愿意,如果您需要调用未知对象/var/function/。。。在没有声明之前,这个系统会为您找到一个解决方案。(我知道这很奇怪,但我很好奇)这是一个非常奇怪的错误处理程序用法。这会让你的代码变得更加复杂,让其他人都无法理解。哈哈,我知道。事实是,一切都是虚无缥缈的!如果您愿意,如果您需要调用未知对象/var/function/。。。在没有声明之前,这个系统会为您找到一个解决方案。(我知道这很奇怪,但我很好奇)