zojjyg
Last Updated: February 25, 2016
·
325
· antony492

Fix Errors Whilst Using Referenced Functions

This function would return an error when called:

function &getAllElements ( ) {
    if (is_array($this->data)) {
        return $this->data;
    }
    return null;
}

The error would be something along the lines of:
"Only variable references should be returned by reference."

A quick and dirty way (and the only way I could figure out) is to set a variable with your null value and return that:

function &getAllElements ( ) {
    if (is_array($this->data)) {
        return $this->data;
    }
    $null = null;
    return $null;
}