Home >Backend Development >PHP Tutorial >How to get the value of private attribute in php

How to get the value of private attribute in php

藏色散人
藏色散人forward
2021-02-11 09:12:192779browse

Using laravel's chunkById paragraph query method, query 2K at a time, and then batch into the database , since this table has not been changed, it can be directly queried and imported

The problem encountered is that the data attribute after the query is an array, which must be manually assembled before it can be directly stored in the database. There are a lot of fields. Just imagine if it can be Get this attribute data directly and then throw it into the array and store it directly in the database

The queried data is like this (recommended: "php video tutorial")
How to get the value of private attribute in php

is a private attribute

Directly (array)$value is like this
How to get the value of private attribute in php

##then directly

$arrTemp['x00* x00attributes'] should be fine. I tried it and it works.

Encapsulate:

public function getProtectedValue($obj, $name) {
    $array = (array)$obj;
    $prefix = chr(0).'*'.chr(0);
    return $array[$prefix.$name];
}
The ASCII code corresponding to x00 in the screenshot is 0. Use chr to convert the ASCII code of 0 into a string. That is, the ASCII code corresponding to chr(0) is x00, and then splicing * is OK

The adjusted code is

$arrTemp = $this->getProtectedValue($value, 'attributes');

The above is the detailed content of How to get the value of private attribute in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete