cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG] Setters/Getters in model, after i fetch an item from model gives errors

Open niden opened this issue 7 months ago • 6 comments

@niden a question i have... hope u understand my bad English- so... is it normal, when i have setters/getters in model, after i fetch an item from model - data now is going though? Lets show u example:

My model:

class Users ... {
    protected ?string $data = null;
    ...
    
    public function setData(?array $data = []): void
    {
        $this->data = implode('-', $data);
    }
}

Before: $test = Models\Users::findFirst(): Now with this release this gives me error... say $data must be array, not string. This is because in DB this field is string.

Anyway... i fixed the function public function setData(null|string|array $data = []): void ... etc, but, just want to know which one is the right behavior.

Originally posted by @borisdelev in https://github.com/phalcon/cphalcon/discussions/16938#discussioncomment-16766565

niden avatar Apr 30 '26 21:04 niden

Resolved in https://github.com/phalcon/cphalcon/pull/16957

Thank you @borisdelev

niden avatar Apr 30 '26 22:04 niden

Amm a question i have- sorry- did this is fixed in 5.13 - i am with that version and issue still persist. Thanku!

borisdelev avatar May 21 '26 11:05 borisdelev

Amm a question i have- sorry- did this is fixed in 5.13 - i am with that version and issue still persist. Thanku!

@borisdelev this should have been addressed in 9b1e7541,

Can you confirm version and perhaps show the full stack trace of the error? I have been using your example as a test.

niden avatar May 24 '26 00:05 niden

Yes, i confirm i have that in 5.13. In my case... i have something like that:

<?php
// in model
protected ?string $password = null;

    public function setPassword(?string $password = null): void
    {
        var_dump('HEHHEHE');exit;
    }

When i retrieve this model, with findFirst for example- will print "hhehehe".

If this should be the right behavior... so, i need to fix my code :)

borisdelev avatar May 25 '26 19:05 borisdelev

@borisdelev I checked this and what you are seeing is the intended behavior after the bug fix.

You could use the orm.disable_assign_setters = true if you want to remove that. Right now hydration matches what assign() does

niden avatar May 28 '26 13:05 niden

Cool. Good to know. Will fix my logick then... Thank u ❤️

borisdelev avatar May 28 '26 13:05 borisdelev