Subscribe For Free Updates!

We'll not spam mate! We promise.

Feb 23, 2013

Only variable references should be returned by reference


Only variable references should be returned by reference :
Consider the following example :
<?php
class myClass {
    public $var = 1;

    public function &getVar() {
        return($this->var);
        }
}

$obj = new myClass;
$value = &$obj->getVar();
?>

The above example should arise the error, 
To solve it like below code:
<?php
class myClass {
    public $var = 1;

    public function &getVar() {
        return $this->var;
        }
}

$obj = new myClass;
$value = &$obj->getVar();
?>
Another Easiest Example is given below :
return $this->auth ? $this->ehlo() : $this->helo();
Change the above line to below one.
$return = $this->auth ? $this->ehlo() : $this->helo();
return $return;

By

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment