How to get the value of private attribute in php

藏色散人
Release: 2023-04-09 18:10:01
forward
2709 people have browsed it

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];
}
Copy after login
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');
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!