Description
Hi, i have a class to operate getters and setters in special way.
When i try to use this class with from object i get error.
"Neither the property "status" nor one of the methods "getStatus()", "isStatus()", "hasStatus()", "__get()" exist and have public access in class "Backend\WorkorderBundle\Entity\WorkorderFilter""
I think it's a bug or missfunction because if i try
var_dump($filter->getStatus());
var_dump($filter->setStatus('aaa'));
var_dump($filter->getStatus());
Everything goes smoothly as expected.
Here is my code
$filter = new WorkorderFilter();
$form = $this->createFormBuilder($filter)
->add('status', 'choice', array(
'choices' => $ref_dict['workorder_status'],
'required' => false,
'empty_value' => '',
'empty_data' => null,
))
->getForm();
class WorkorderFilter
{
private $status;
private $statusUpdatedFrom;
private $statusUpdatedTo;
//..
public function __call($name , array $arguments)
{
$var_array = get_class_vars(__CLASS__);
$var = strtolower(substr($name, 3, 1)) . substr($name, 4);
if (array_key_exists($var, $var_array)) {
if (substr($name, 0, 3) == 'get') {
return $this->$var;
} elseif ((substr($name, 0, 3) == 'set') && (isset($arguments[0]))) {
$this->$var = $arguments[0];
return $this;
}
}
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_NOTICE);
}
//get array of values that are not equal to
public function getDiff($object)
{
$var_array = get_class_vars(__CLASS__);
$result = array();
$bFlag = false;
foreach (array_keys($var_array) as $var) {
$getterName = 'get'. strtoupper(substr($var, 0, 1)) . substr($var, 1);
if ($this->$var != $object->$getterName()) {
$result[$var] = $this->$var;
$bFlag = true;
}
}
return ($bFlag) ? $result : false;
}
}