来自wordpress的功能,我不能很好地遵循

时间:2011-06-23 03:54:46

标签: php wordpress

function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) {
    if ( isset( $GLOBALS['custom_background'] ) )
        return;

    if ( empty( $header_callback ) )
        $header_callback = '_custom_background_cb';

    add_action( 'wp_head', $header_callback );

    add_theme_support( 'custom-background', array( 'callback' => $header_callback ) );

    if ( ! is_admin() )
        return;
    require_once( ABSPATH . 'wp-admin/custom-background.php' );
    $GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback );
    add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) );
}

1,$GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback );使用了符号&和行的含义是什么?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

这意味着您要为globals数组中的变量分配引用。

$GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback );

基本上,如果更改$GLOBALS['custom_background']的值,则会影响原始变量本身(Custom_Background)。

http://www.php.net/manual/en/language.references.php

请记住,默认情况下,对象是通过引用传递的。