Custom Result Objects & Setter |
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 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.
Why do you think __set() is not called?
If you have "protected $name" properties declared, they are automatically filled with values.
When there is no property, __set() is executed. BUT, you re-check the declaration of the property (they are already filled in). property_exists() is unnecessary. PHP Code: // Class (11-03-2023, 10:26 PM)ozornick Wrote: If you have "protected $name" properties declared, they are automatically filled with values. What do you mean by automatically? How? See https://3v4l.org/FZSap
See https://www.php.net/manual/en/mysqli-res...object.php
Mysqli creates an object a little differently. As Reflection? Props id, user_id, title, is_read not calling __set(). body, created_at run __set(). What did I say wrong? PHP Code: // Setter |
Welcome Guest, Not a member yet? Register Sign In |