-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phalcon\Mvc\Model __set method failure #11286
Comments
Does anyone here have any thoughts with this one? I've been trying to rewrite it possibly using the ReflectionProperty class, but was getting segfault errors from it. Now I am getting real errors on TravisCI though I cannot yet run the unit tests locally. P.S. Is there a guide somewhere about getting set-up for running test locally? |
Could you please check now |
Minor rewrite to assign and __set issue #11286
[2.0.x] Issue #11286 - Model property visibility and setter functionality
I cant access my model aliases (relations) anymore with 2.1.x |
@michanismus Can you please provide script to reproduce? |
@sergeyklay I opened a new issue #11427 |
@bmoore Issue is solved? |
Sorry for push, but we need a solution. The new behaviour breaks a lot of code for me! Why should the model always search and use an available setter? If I want to use a setter, I call it! I think it would better to extend the Model class to gain "auto use setter" behaviour and revert the changes. |
@michanismus +1 to the optional behaviour parameter, so we can decide if the object uses or not the auto use setter. and of course, + 1 to autosetter use, afterFetch and beforeSave are really difficult to manage if I want my model to take care of data transformations etc |
Wait wait wait. I don't understand, when they should be set ? It's normal behaviour. Afterfetch means AFTER FETCHING, like SELECTING, SETTING VALUES ETC |
[edited: wrong conclusion] I did a clean test from scratch and everything is working fine. My fault. |
After reviewing the documentation, and working with phalcon models. I found an issue using model setters. https://docs.phalconphp.com/en/latest/reference/models.html#public-properties-vs-setters-getters mentions that we can automagically use a method named "set" + camelize(property) to handle setting non-public properties. This however is not what is happening.
Consider the example
After digging through the code, I noticed that the model magic
__set
method made no check for the possible setter, and instead just assigns the property.This makes no mention or use of the possible setter.
Furthurmore second to last line completely bypasses the purpose of making a property private or protected, as it will always set the property regardless.
I can see the line in
Model::assign()
that utilizes the possible setter.I believe this should be refactored so the possible setter is utilized in
__set
and also fix the issue with__set
completely bypassing private and protected properties.I will provide a proof-of-concept patch in the near future.
The text was updated successfully, but these errors were encountered: