What are the potential pitfalls of using stdClass objects in PHP arrays?

When using stdClass objects in PHP arrays, one potential pitfall is that it can be difficult to access and manipulate the data stored within these objects, especially when dealing with nested structures. To solve this issue, consider converting stdClass objects to associative arrays, which provide easier access and manipulation of data.

// Convert stdClass objects to associative arrays
function convertStdClassToArray($data) {
    if (is_object($data)) {
        $data = get_object_vars($data);
    }
    
    if (is_array($data)) {
        return array_map('convertStdClassToArray', $data);
    } else {
        return $data;
    }
}

// Example usage
$stdClassObject = new stdClass();
$stdClassObject->name = 'John Doe';
$stdClassObject->age = 30;

$array = convertStdClassToArray($stdClassObject);

print_r($array);