I can't convert PHP object to an array and send it to JavaScript file as an object. Here is what I'm doing: Getting user object from database - it looks like this:
Array
(
[0] => AppBundle\AdminBundle\Entity\AdminUser Object
(
[id:protected] => 1
[name:protected] => Kamil
[surname:protected] => Stangelj
[birthdate:protected] => DateTime Object
(
[date] => 1996-01-28 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[email:protected] => kamiltomice@gmail.com
[login:protected] => Sztanga
[password:protected] => $2y$15$qyD9tbeIcXqRKTQeUJEiLehWo16XKy447NVWU7q/VyvYSD0k61f6C
[image:protected] => resources_admin/images/upload/users/1510092373jDuHxJkOnGp1RNxTOy0OBez nazwy-1.png
[role:protected] => ["1","2","3","4","5","6","7","8","9","10"]
[lock_date:protected] => DateTime Object
(
[date] => 2017-12-17 15:20:08.000000
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[is_active:protected] => 1
[is_non_locked:protected] => 1
[lock_info:protected] =>
)
)
Another step I was doing is to convert it via object_to_array function (from that example that I get from this Stack answer - this answer also didn't help me). This is the function from the link above:
public function objectToArray($data)
{
if(is_array($data) || is_object($data))
{
$result = array();
foreach($data as $key => $value) {
$result[$key] = UsefulController::objectToArray($value);
}
return $result;
}
return $data;
}
And there's a problem because that function returns me an empty array:
Array
(
[0] => Array
(
)
)
If someone dind't understood my problem. I want to convert PHP object that i pointed first to an array and pass it back to my JavaScript file store it as an object.
In the very very big nutshell:
INPUT DATA: PHP Object
OUTPUT DATA: JavaScript Object