The $this problem in the php class

variables in a class

    public $id;

    
    public $group_id;

    
    public $parent_id;


    public $type;


    public $name;

    
    public $description;

    
    public $is_required;

    
    public $can_delete = "1";

    
    public $field_order;

    
    public $option_order;


    public $order_by;

    
    public $is_default_option;

    
    protected $default_visibility;

    
    protected $allow_custom_visibility;

    
    public $do_autolink;

    
    public $type_obj = null;

    
    public $data;

    
    protected $member_types;

public function __construct( $id = null, $user_id = null, $get_data = true ) {

        if ( ! empty( $id ) ) {
            $this->populate( $id, $user_id, $get_data );

        // Initialise the type obj to prevent fatals when creating new profile fields.
        } else {
            $this->type_obj            = bp_xprofile_create_field_type( "textbox" );
            $this->type_obj->field_obj = $this;
        }
    }

one of the paragraphs

public function fill_data( $args ) {
        if ( is_object( $args ) ) {
            $args = (array) $args;
        }

        $int_fields = array(
            "id", "is_required", "group_id", "parent_id", "is_default_option",
            "field_order", "option_order", "can_delete"
        );

        foreach ( $args as $k => $v ) {
            if ( "name" === $k || "description" === $k ) {
                $v = stripslashes( $v );
            }

            // Cast numeric strings as integers.
            if ( true === in_array( $k, $int_fields ) ) {
                $v = (int) $v;
            }

            $this->{$k} = $v;
        }

        // Create the field type and store a reference back to this object.
        $this->type_obj            = bp_xprofile_create_field_type( $this->type );
        $this->type_obj->field_obj = $this;

    }

bp_xprofile_create_field_type is a public function, and the returned data is

{"name":"","category":"","accepts_null_value":false,"supports_options":true,"supports_multiple_defaults":false,"supports_richtext":false,"field_obj":null}

what exactly does $this in the function fill_data mean

Does

$this represent the $this- > {$k} array just generated?

Php
Mar.14,2021

the current object instance


$this is a reference to the caller. Since it is a reference, it has the same effect as an instance, such as accessing properties, methods, or assigning values to properties. However, $this does not represent an instance of a class just because it appears in a class. For example, in the case of inheritance, $this may point to an instance of a subclass.

Menu