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; | |
} |
Hi,
I have to add dash to the REGEX because Oracle PHP driver returns name with dash in it:
array (
'ptip_sif' => '4',
'pptip_opis' =>
OCI-Lob::__set_state(array(
'descriptor' => NULL,
)),
),
Instead of:
$dump = preg_replace('/[a-zA-Z_]+::__set_state/', '', $dump);
... here is REGEX that contains dash "\-"
$dump = preg_replace('/[a-zA-Z_\-]+::__set_state/', '', $dump);
Regards,
Darko
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for writing this man. Saved my but there. If there was some way to tip you I definitely would!