Skip to content

Commit

Permalink
[#13518] - Added check to __isset for potential getter and changed th…
Browse files Browse the repository at this point in the history
…e exception text
  • Loading branch information
niden committed Dec 25, 2019
1 parent 2a1d3fa commit 5633dfd
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 142 deletions.
15 changes: 12 additions & 3 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
*/
public function __isset(string! property) -> bool
{
var modelName, manager, relation;
var manager, method, modelName, relation, result;

let modelName = get_class(this),
manager = <ManagerInterface> this->getModelsManager();
Expand All @@ -339,7 +339,16 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
property
);

return typeof relation == "object";
if typeof relation === "object" {
let result = true;
} else {
// If this is a property
let method = "get" . camelize(property);

let result = method_exists(this, method);
}

return result;
}

/**
Expand Down Expand Up @@ -457,7 +466,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,

if unlikely !manager->isVisibleModelProperty(this, property) {
throw new Exception(
"Property '" . property . "' does not have a setter."
"Cannot access property '" . property . "' (not public)."
);
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/_data/fixtures/models/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ class Invoices extends Model
public $inv_total;
public $inv_created_at;

private $secretValue;
private $superSecret;

public function initialize()
{
$this->setSource('co_invoices');
}

public function setSecretValue($value)
{
$this->secretValue = $value;
}

public function getSecretValue()
{
return $this->secretValue;
}
}
Loading

0 comments on commit 5633dfd

Please sign in to comment.