new operator and reference error

后端 未结 3 1813
陌清茗
陌清茗 2021-01-28 09:50
 $class_name = \'MDB2_Statement_\'.$this->phptype;
        $statement = null;
        $obj =& new $class_name($this, $statement, $positions, $query, $types, $resu         


        
相关标签:
3条回答
  • 2021-01-28 10:01

    The only thing PHP is complaining about is this:

    $obj =& new $class_name...
          ^
    

    You do not need and should not use assignment by reference anymore, since objects are always references in PHP 5. Just get rid of the &, and that's it.

    0 讨论(0)
  • 2021-01-28 10:06

    You can create reference of an object in php 5.3.10 using this way.

    $firstObj = new something();
    $referenceObj = &$firstObj;
    
    0 讨论(0)
  • 2021-01-28 10:11

    Why do you even use the reference operator with objects? A object is placed in the memory and all variables bound to it will change its memory.

    In other words

    $a1 = new stdClass;
    $a2 = $a1;
    

    would have the same affect as:

    $a1 = 1000;
    $a2 = &$a1;
    
    0 讨论(0)
提交回复
热议问题