Description
Questions? Forum: https://phalcon.link/forum or Discord: https://phalcon.link/discord
Describe the bug
During hydration using Resultset::HYDRATE_RECORDS mode Models protected/private property values sets like they are public ones instead to be set using setters.
To Reproduce
Generate any model that uses setters and getters. At setters throw any kind of exception. Retrieving record by calling Model::findFirst() expected that exception will be thown in setters. But there is no any exception is thrown and we have a Model instance with setted values.
Steps to reproduce the behavior:
class User extends \Phalcon\Mvc\Model
{
protected $id;
public function setId($id)
{
throw new \Exception('Setter is called');
}
public function getId()
{
return $this->id;
}
}
$user = User::findFirst(10);
// Exception is expected but not observed
echo $user->id; // output: 10
$user = new User;
$user->id = 10;
// Exception is thrown as expected
Also there is another unexpected behaviour. If we override cloneResultMap method and create a new instance of base model and set a value for protected property no exception is thown as expected.
class User extends \Phalcon\Mvc\Model
{
public static function cloneResultMap (
$base,
array $data,
$columnMap,
int $dirtyState = 0,
bool $keepSnapshots = null
): \Phalcon\Mvc\ModelInterface
{
$class = get_class($base);
$instance = new $class;
$instance->id = 10; // the value is set like a public, no exception is thrown
return $instance;
}
}
Details
Environment:
OS: Linux UBT 4.15.0-74-generic #84-Ubuntu SMP Thu Dec 19 08:06:28 UTC 2019 x86_64
PHP Version: 7.4.2
PHP SAPI: cli
PHP Bin: /usr/bin/php7.4
PHP Extension Dir: /usr/lib/php/20190902
PHP Bin Dir: /usr/bin
Loaded PHP config: /etc/php/7.4/cli/php.ini
Versions:
Phalcon DevTools Version: 4.0.1
Phalcon Version: 4.0.3
AdminLTE Version: 2.3.6
Metadata
Metadata
Type
Projects
Status