Php 使用全局变量的函数包含代码时出现不支持的操作数类型错误
如果我使用PHP的INCLUDE指令,我有一段代码可以很好地工作。但是,若在另一个函数中执行包含,则在包含的文件的最后一行上会得到错误不支持的操作数类型 这是工作代码Php 使用全局变量的函数包含代码时出现不支持的操作数类型错误,php,include,global,Php,Include,Global,如果我使用PHP的INCLUDE指令,我有一段代码可以很好地工作。但是,若在另一个函数中执行包含,则在包含的文件的最后一行上会得到错误不支持的操作数类型 这是工作代码 <?php // main.php unset($doc_list, $doc_idx); $doc_idx = 0; $doc_list = Array( 'locations' => Array( 'Places', 'locations' ) ); incl
<?php // main.php
unset($doc_list, $doc_idx);
$doc_idx = 0;
$doc_list = Array(
'locations' => Array( 'Places', 'locations' )
);
include( 'nation.php' );
$doc_list = $doc_list + Array(
'-'.(++$doc_idx).'-' => Array( 'Town A', '' ),
'-'.(++$doc_idx).'-' => Array( 'Town B', '' ),
'town_b_today' => Array( 'Today', 'locations' ),
'-'.(++$doc_idx).'-' => Array( 'Saint-Paulet', '' )
);
makeDocsFrom( 'places', $doc_list, 'site' );
?>
借
在哪里
请注意,nation.php中的第4行是
);
感谢您的帮助。我怀疑这个问题与
global $doc_idx, $doc_list ; // For usage inside pages
但是我不明白为什么。所以这个
plain\u include
函数的唯一目的是获取“更好的”错误消息…?这不值得使用globals IMHO,很可能你会在这里制造更多的问题,而不是解决问题。不,函数做其他事情,但与问题无关。我只是删除了一些说明,使我的帖子更简单。当然,我验证了简化函数会给出相同的错误,也就是说,被删除的指令不涉及错误。
plain_include( 'nation.php' );
function plain_include($file) {
global $doc_idx, $doc_list ; // For usage inside pages
if (file_exists($file)) {
include($file);
} else {
echo '<p class="micro">Not found. URL: '.$file.'</p>';
}
}
Fatal error: Unsupported operand types in ...nation.php on line 4
);
global $doc_idx, $doc_list ; // For usage inside pages