php类 this,php 类中$this问题

本文详细解析了PHP类中的fill_data方法,该方法用于填充类的属性值。通过对$args$进行处理并转换,将数值型字符串转换为整数,然后赋值给对应的类变量。同时,介绍了如何通过bp_xprofile_create_field_type创建字段类型,并将其与当前对象关联。此代码段适用于数据模型构建,特别是用户配置文件字段的管理。
摘要由CSDN通过智能技术生成

一个类中的变量

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;

}

}

其中一段

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是一个公共函数,返回数据是

{"name":"单选按钮","category":"多项资料","accepts_null_value":false,"supports_options":true,"supports_multiple_defaults":false,"supports_richtext":false,"field_obj":null}

请问函数fill_data 中$this到底是什么意思呢

$this代表刚刚生成的$this->{$k}数组吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值