Voting

: max(eight, two)?
(Example: nine)

The Note You're Voting On

jszoja at gmail dot com
7 years ago
Be aware of a reference to another reference. It is probably bad practice to even do that.

<?php
   
class Obj1 { public $name = 'Obj1'; }
    class
Obj2 { public $name = 'Obj2'; }

   
$objects = [];
   
$toLoad = [ 'Obj1', 'Obj2' ];

    foreach(
$toLoad as $i => $obj )
    {
       
$ref = new $obj();
       
$objects[$i] =& $ref; // a reference to a reference
        // $objects[$i] = $ref; // that would work
   
}

    echo
$objects[0]->name;
       
// outputs 'Obj2' !
?>

<< Back to user notes page

To Top