When I try to bind overloaded property in PDOStatement::bindParam method,
$stmt->bindParam(':'.$field.'', $this->$field, $pdoparam);
...
public function __get($param)
{
if(isset($this->$param))
return $this->$param;
}
I get a notice
Notice: Indirect modification of overloaded property Msgs::$posttime has no effect in ...
After some research I found a bug report about the similar problem at php.net. The proposed solution is to add a & before __get definition.
&__get(...
But when I try to do that I get another notice
Notice: Only variable references should be returned by reference in ...
PHP version is 5.3.8.
Is there any solution to this problem?
PDOStatement::bindParamrequires a reference and potentially modifies the argument that was passed to it (converts it to the most appropriate type, or writes the result to it if it’s an OUT/INOUT parameter).PDOStatement::bindValuedoesn’t take a reference and doesn’t modify the argument.__getreturns the value of$this->$parambut doesn’t actually make it a reference to the$this->$param, and making a reference to the returned value produces this notice. It is not specific to PDO, even a simple$x =& $this->$paramwill trigger the same notice. UsebindValueinstead ofbindParamto avoid this.Some more explanation about a non-reference
__get: https://stackoverflow.com/a/5337433/1233508