How does using ORM frameworks like Doctrine or RedBean compare to implementing custom magic methods for property access in PHP classes?

Using ORM frameworks like Doctrine or RedBean allows developers to easily map database tables to PHP objects, handle relationships between objects, and perform database operations without writing SQL queries manually. On the other hand, implementing custom magic methods for property access in PHP classes requires more manual work and can be error-prone if not implemented carefully.

// Example of using Doctrine ORM framework to map a database table to a PHP object

// Define a User entity class
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $username;

    // Getters and setters for properties
    public function getId()
    {
        return $this->id;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function setUsername($username)
    {
        $this->username = $username;
    }
}

// Usage of the User entity
$user = new User();
$user->setUsername('john_doe');

// Save the user to the database using Doctrine EntityManager
$entityManager->persist($user);
$entityManager->flush();