What are the potential pitfalls of using phtml files as models in PHP MVC frameworks, and how can developers avoid them?

Using phtml files as models in PHP MVC frameworks can lead to a lack of separation of concerns and make the code harder to maintain. To avoid this pitfall, developers should strictly adhere to the MVC pattern by keeping models separate from views. Models should contain business logic and data manipulation, while views should only handle presentation logic.

// Incorrect way of using phtml file as a model
// index.phtml

<?php
class UserModel {
    public function getUsers() {
        // code to fetch users from database
    }
}
?>

// Correct way to separate models from views
// UserModel.php

<?php
class UserModel {
    public function getUsers() {
        // code to fetch users from database
    }
}
?>

// index.phtml

<?php
$userModel = new UserModel();
$users = $userModel->getUsers();
foreach ($users as $user) {
    echo $user['username'];
}
?>