PHP notification when binding an overloaded property in PDOStatement :: bindParam

When I try to bind an overloaded property in the PDOStatement :: bindParam method,

$stmt->bindParam(':'.$field.'', $this->$field, $pdoparam); ... public function __get($param) { if(isset($this->$param)) return $this->$param; } 

I get a notification

 Notice: Indirect modification of overloaded property Msgs::$posttime has no effect in ... 

After some research, I found a bug report of a similar problem on php.net. The proposed solution is to add the definition of a and before __get.

 &__get(... 

But when I try to do this, I get another notification

 Notice: Only variable references should be returned by reference in ... 

The PHP version is 5.3.8.

Is there any solution to this problem?

+4
source share
2 answers

PDOStatement::bindParam requires a reference and potentially modifies the argument that was passed to it (converts it to the most suitable type or writes the result to it if it has an OUT / INOUT parameter).

PDOStatement::bindValue does not accept the link and does not change the argument.

__get returns the value of $this->$param , but doesn’t actually refer to $this->$param , and a reference to the return value triggers this notification. This does not apply to PDO, even a simple $x =& $this->$param triggers the same notification. Use bindValue instead of bindParam to avoid this.

A few more clarifications regarding the __get link: fooobar.com/questions/396237 / ...

+5
source

If you changed your code to &__get(... , I think you should also change the following line:

 $stmt->bindParam(':'.$field.'', &$this->$field, $pdoparam); 
0
source

Source: https://habr.com/ru/post/1398455/


All Articles