Last active
January 12, 2018 14:35
-
-
Save fedir/7871162 to your computer and use it in GitHub Desktop.
Conversion of an object to array with var_export / eval // via http://www.kormoc.com/2012/11/18/convert-a-php-object-to-an-array/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function toArray($object) { | |
$dump = '$dump = '.var_export($object, true); | |
$dump = preg_replace('/object\([^\)]+\)#[0-9]+ /', 'array', $dump); | |
$dump = preg_replace('/[a-zA-Z_]+::__set_state/', '', $dump); | |
$dump = str_replace(':protected', '', $dump); | |
$dump = str_replace(':private', '', $dump); | |
$dump .= ';'; | |
eval($dump); | |
return $dump; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I have to add dash to the REGEX because Oracle PHP driver returns name with dash in it:
Instead of:
... here is REGEX that contains dash "\-"
Regards,
Darko