-
-
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
unset object property makes it private #15276
Comments
Hello @konsultaner I can't reproduce your error $user = User::findFirst(1);
var_dump($user->id); // int(1)
unset($user->id);
var_dump($user->id); // Notice: Access to undefined property User::id
$user->custom = 'value';
var_dump($user->custom); // string(5) "value"
unset($user->custom);
var_dump($user->custom); // Notice: Access to undefined property User::custom PHP version:
Phalcon Version:
|
ok, that is strange, but this is what happens on my machine. I'll try more investigations on this. |
Didn't notice that you are using version https://github.com/phalcon/zephir/blob/master/CHANGELOG.md#01218---2020-04-25
Try to make properties public, ou use getters |
And this is correct PHP behavior, which was fixed after <?php
class Test
{
protected $protected = 1;
public $public = 2;
private $private = 3;
}
$class = new Test();
var_dump($class->public);
unset($class->public);
var_dump($class->public); // Notice: Undefined property: Test::$public
unset($class->protected); // Fatal error: Uncaught Error: Cannot access protected property Test::$protected Sandbox - http://sandbox.onlinephpfunctions.com/code/efae33dd9145a4420dc82e676716d61517d36b2c |
@Jeckerson I don't know what went wrong, but my field was public, but what I did was: <?php
class Test extends Model // Its a phalcon model
{
protected $protected = 1;
public $public = 2;
private $private = 3;
}
$class = new Test();
var_dump($class->public);
unset($class->public);
var_dump($class->public); // Notice: Undefined property: Test::$public
$class->public = 3; // Fatal error: Uncaught Phalcon\Mvc\Model\Exception: Cannot access property 'public' (not public) |
To fix this, need to review this x2 blocks of code: if property_exists(this, property) {
let manager = this->getModelsManager();
if unlikely !manager->isVisibleModelProperty(this, property) {
throw new Exception(
"Cannot access property '" . property . "' (not public)."
);
}
} final public function isVisibleModelProperty(<ModelInterface> model, string property) -> bool
{
var properties, className;
let className = get_class(model);
if !isset this->modelVisibility[className] {
let this->modelVisibility[className] = get_object_vars(model);
}
let properties = this->modelVisibility[className];
return array_key_exists(property, properties);
} Unset property will exist even after <?php
class Test
{
public $public;
protected $protected;
private $private;
}
$test = new Test();
var_dump(property_exists($test, 'public')); // true
unset($test->public);
var_dump(property_exists($test, 'public')); // true |
@Jeckerson, is someone working on this issue? |
Im on it, will be fixed asap |
Resolved in #15719 |
I'm using PHP 7.4 with phalcon 4.1.0. The following code raises an Exception:
With phalcon 4.0.5 on PHP 7.3 it worked as expected. I'm not sure if this is a PHP issue or Phalcon. You may aswell close it if this is not Phalcon related.
The text was updated successfully, but these errors were encountered: