使用just时没有区别echo. 不同之处在于unset():
function test_unset_1()
{
global $post;
unset( $post );
}
function test_unset_2()
{
unset( $GLOBALS[\'post\'] );
}
test_unset_1();
echo $GLOBALS[\'post\']->ID; // will work
test_unset_2();
echo $GLOBALS[\'post\']->ID; // will fail
原因是
unset() 在第一种情况下仅销毁局部引用,在第二种情况下销毁真实的全局对象。
为了便于阅读,请始终使用$GLOBALS[\'post\']. 更容易看到变量的来源。