The 5th Annual China PHP Conference

Voting

Please answer this simple SPAM challenge: five plus one?
(Example: nine)

The Note You're Voting On

wernerdegroot at nospam dot gmail
7 years ago
In the following case you don't have to use = & operator when returning a reference:

<?php

   
class a {
        public
$a = 1;
    }
   
    class
b {
        static
$var;
       
        public static function &
gvar($i) {
            if(!(isset(
b::$var[$i]))) {
               
b::$var[$i] = new a;
            }
           
            return
b::$var[$i];
        }
    }
   
   
$b = new b;
   
$a = b::gvar(1);
   
$a->a = 14;
   
   
$c = b::gvar(1);
    echo
$c->a; // 14
?>

Note the $a = b::gvar(1) instead of $a = & b::gvar(1)!!!

<< Back to user notes page

To Top