I’m looking at Doctrine 2 and Symfony documentation for creating a model class.There are several code snippets where a getProperty and setProperty is used within the class, and these are somehow used automatically when a value is assigned directly to the property. This is different then the typical get/set magic methods, and the sample code I have come across does not implement any custom magic methods, so I believe this is handled by Doctrine somewhere.
From what I’ve read, Doctrine implements accessors and mutators. Maybe I missed a package when downloading Pear, or maybe I’m not including something in my script.
For example:
class User {
public $name;
public function getName()
{
// Do stuff
}
}
$user = new User();
$foo = $user->name; // getName is called
Note: I’m looking for a Doctrine specific solution. I know this can be done in someway with PHP, but I want to use Doctrine’s native functions.
Edit: Updated to clarify how this differs from typical get/set magic methods, and note.
If there is a method
getSomethingorsetSomethingit will be called when accessing the properties directly.As I read in this documentation page, it is exactly what the code above does what Doctrine does. But it calls the method
_set('fieldName', 'value').