Questions about transcoding in PHP arrays

Source: Internet
Author: User
Problems with PHP array transcoding
Public Function Array_iconv ($in _charset, $out _charset, $arr) {
Return eval (' Return '. Iconv ($in _charset, $out _charset,var_export ($arr, true). '; ');
}
I had this problem when I was 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 has:

_set_state ()

Static object __set_state (array $properties)
This static method is called when Var_export () is called (Valid from PHP 5.1.0).

The only parameter to this method is an array that contains the by array (' property ' = = value, ...) The class properties of the format arrangement.

Example #4 using __set_state () > (PHP 5.1.0 and later support)
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.