php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

table()->update fails in php 5.3

Open sblackstone opened this issue 14 years ago • 2 comments

Using the mass update feature as currently documented does not work in PHP 5.3..

PHP 5.3 deprecated call-time pass by reference..

As documented: Blarg::table()->update(array(...), array(...))

will throw an error that the parameter cannot be passed by reference.

If you do

$a = array( ... ); $b = array( ... ); Blarg::table()->update($a,$b);

Then it is ok..

I would suggest we just remove the pass by reference:

--- a/lib/Table.php +++ b/lib/Table.php @@ -341,7 +341,7 @@ class Table return $this->conn->query(($this->last_sql = $sql->to_s()),$values); }

  •   public function update(&$data, $where)
    
  •   public function update($data, $where)
    {
            $data = $this->process_data($data);
    

sblackstone avatar May 05 '11 15:05 sblackstone

I've always failed at it and never thought of making that change… but yes maybe.

Or should we avoid exposing Model::table() and create something in the flavour of Model::delete_all() instead?

Like this:

<?php

Blog::update_all(array(
    'set' => array('is_active' => false),
    'conditions' => array('id' => array(1,2,3)
));
echo Blog::table()->last_sql;
// update blogs set is_active = ? where id in (?);

greut avatar May 05 '11 20:05 greut

+1

ttrig avatar Mar 25 '15 15:03 ttrig