Php array transcoding problems

Source: Internet
Author: User
Php array transcoding publicfunctionarray_iconv ($ in_charset, $ out_charset, $ arr) {returneval ('Return '. iconv ($ in_charset, $ out_charset, var_export (php array transcoding problem)
Public function array_iconv ($ in_charset, $ out_charset, $ arr ){
Return eval ('Return '. iconv ($ in_charset, $ out_charset, var_export ($ arr, true ).';'));
}
This problem occurs during transcoding.
Fatal error: Call to undefined method stdClass ::__ set_state () in D: \ soft \ apache \ htdocs \ webtest \ arrayiconv. func. php (5): eval () 'd code on line 1

------ Solution --------------------
The manual includes:

_ Set_state ()

Static object _ set_state (array $ properties)
When var_export () is called, this static method is called (effective from PHP 5.1.0 ).

The unique parameter of this method is an array, which contains class attributes in array ('properties' => value,...) format.

Example #4 use _ set_state ()> (supported by PHP 5.1.0 and later)
PHP code
  var1 = $an_array['var1'];        $obj->var2 = $an_array['var2'];        return $obj;    }}$a = new A;$a->var1 = 5;$a->var2 = 'foo';eval('$b = ' . var_export($a, true) . ';'); // $b = A::__set_state(array(                                            //    'var1' => 5,                                            //    'var2' => 'foo',                                            // ));var_dump($b);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.