php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30616 Cant return as reference from offsetget() for mysqli_stmt->bind_param()
Submitted: 2004-10-29 21:26 UTC Modified: 2004-10-30 13:21 UTC
From: john at milsson dot nu Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.0.2 OS: Windows
Private report: No CVE-ID: None
 [2004-10-29 21:26 UTC] john at milsson dot nu
Description:
------------
Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference

when I try to use $mysqli_stmt->bind_param('s',$arrayAccessObj['offset']);

even though offsetget is declared as

function &offsetGet($key) {
    return $this->{'_'.strtolower($key)};
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-30 00:56 UTC] derick@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2004-10-30 04:51 UTC] john at milsson dot nu
Tried to trigger this at home. But it works as expected.

But: 
  1. This is a linux machine.
  2. Home compiled
  3. I'm not stressed out...
  4. The code is much cleaner.

My guess is that I screwd up with one of the '&' in some deep nested retuen tree


As I said, this code works:
class ArrayObj implements ArrayAccess {

    private $_val;
    public  $valAsProp;

    function __construct($val){
        $this->_val = $val;
        $this->valAsProp =& $this->_val;
    }
    //
    // ArrayAccess interface
    //
    function  offsetExists($key)   { return isset($this->{'_'.$key});       }
    function &offsetGet($key)      { return       $this->{'get'.ucfirst($key)}();    }
    function  offsetSet($key,$val) {              $this->{'_'.$key} = $val; }
    function  offsetUnset($key)    {              $this->{'_'.$key} = null; }

    function &__get($key)          { return       $this->{'_'.$key};        }
    
    function &getVal() {
        return $this->_val;
    }
 }

$arrayobj = new ArrayObj(new ArrayObj('an other val'));

$db = new mysqli('localhost');
$stmt = $db->prepare("SELECT ? as `val`");
//$stmt->bind_param('s', $arrayobj->valAsProp);
//$stmt->bind_param('s', $arrayobj->val);
$stmt->bind_param('s', $arrayobj['val']['val']);
$stmt->execute();
$stmt->bind_result($res);
$stmt->fetch();
$stmt->close();

echo "\n$res\n";

?>
 [2004-10-30 13:21 UTC] derick@php.net
Not a bug in PHP then -> bogus.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun May 16 22:01:24 2021 UTC