Hi, I started to use CI4 three days ago and today I'm facing a problem with "Custom Result Objects". Here is the class of my custom object :
PHP Code:
class Transaction
{
protected int $id;
protected string $name;
protected float $amount;
public function __get($key)
{
if (property_exists($this, $key)) {
return $this->{$key};
}
}
public function __set($key, $value)
{
if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
}
The problem is when I'm using the function "getCustomResultObject" the "__set" method is never called, attributes are directly updated. Indeed, I tried to modify the setter to update my attributes using the $key & $value variables to do some operations, but the setter is never called. That is strange because I saw in the documentation :
Quote:The object will have all values returned from the database set as properties. If these have been declared and are non-public then you should provide a __set() method to allow them to be set.
And indeed if I remove the "__set" method, I get a error message "Cannot access protected property App\Entities\Transaction::$name". So the __set method is necessary to update the "protected" attributes, but the method is never used. So is it a bug, or I missed something ?
Thanks for your help.